More Division optimization using match and simplify
Marc Glisse
marc.glisse@inria.fr
Sat Nov 21 18:54:00 GMT 2015
On Tue, 17 Nov 2015, Hurugalawadi, Naveen wrote:
> Please find attached the patch that moves some more division optimizations
> from fold-const using match and simplify.
First, note that we are in stage 3, so this all may have to wait until
sometime around March or April next year unless it is fixing some bug.
+/* Simplify A / (B << N) where A and B are positive and B is a power of 2,
+ to A >> (N + log2(B)). */
+(simplify
+ (floor_div (convert? @0) (lshift @1 INTEGER_CST@2))
I don't think the fold-const code was asking for @2 to be a constant. You
will never see (lshift cst1 cst2) in match.pd, it has already been folded
to a constant.
+ (if ((TYPE_UNSIGNED (type)
+ || tree_expr_nonnegative_warnv_p (@0, NULL))
+ && integer_pow2p (@1)
Note that you can write integer_pow2p@1 in the pattern directly if you
want.
+ && tree_int_cst_sgn (@1) > 0
+ && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (with
+ { tree pow2 = build_int_cst (TREE_TYPE (@2), wi::exact_log2 (@1));
+ tree temp = const_binop (PLUS_EXPR, TREE_TYPE (@2), @2, pow2); }
Hmm, maybe you could do the log and plus using wi and only build a single
tree at the end, for a slight economy?
+ (rshift (convert @0) { temp; }))))
+
+/* Convert A/B to A/B */
+(for div (CEIL_DIV_EXPR FLOOR_DIV_EXPR)
+ (simplify
+ (div (convert? @0) (convert? @1))
+ (if (wi::multiple_of_p (@0, @1, TYPE_SIGN (type)))
+ (exact_div (convert @0) (convert @1)))))
Sorry, using wi::multiple_of_p makes no sense here. It can only work on
constants, but for constants we have constant propagation.
--
Marc Glisse
More information about the Gcc-patches
mailing list