From: Richard Biener Date: Tue, 7 Jul 2015 14:12:44 +0000 (+0000) Subject: fold-const.c (fold_binary_loc): Move (X & C2) << C1 -> (X << C1) & (C2 << C1) simplif... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=98e30e515f184bd63196d4d500a682fbfeb9635e;p=gcc.git fold-const.c (fold_binary_loc): Move (X & C2) << C1 -> (X << C1) & (C2 << C1) simplification ... 2015-07-07 Richard Biener * fold-const.c (fold_binary_loc): Move (X & C2) << C1 -> (X << C1) & (C2 << C1) simplification ... * match.pd: ... here. Add (X * C1) % C2 -> 0 simplification pattern derived from extract_muldiv_1. * gcc.dg/vect/vect-over-widen-3-big-array.c: Adjust. From-SVN: r225517 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 988fce30781..b1b3f7f9589 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-07-07 Richard Biener + + * fold-const.c (fold_binary_loc): Move + (X & C2) << C1 -> (X << C1) & (C2 << C1) simplification ... + * match.pd: ... here. + Add (X * C1) % C2 -> 0 simplification pattern derived from + extract_muldiv_1. + 2015-07-07 Kaz Kojima PR target/66780 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index d896d7a1675..23ef423df78 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11194,27 +11194,6 @@ fold_binary_loc (location_t loc, prec) == 0) return TREE_OPERAND (arg0, 0); - /* Fold (X & C2) << C1 into (X << C1) & (C2 << C1) - (X & C2) >> C1 into (X >> C1) & (C2 >> C1) - if the latter can be further optimized. */ - if ((code == LSHIFT_EXPR || code == RSHIFT_EXPR) - && TREE_CODE (arg0) == BIT_AND_EXPR - && TREE_CODE (arg1) == INTEGER_CST - && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) - { - tree mask = fold_build2_loc (loc, code, type, - fold_convert_loc (loc, type, - TREE_OPERAND (arg0, 1)), - arg1); - tree shift = fold_build2_loc (loc, code, type, - fold_convert_loc (loc, type, - TREE_OPERAND (arg0, 0)), - arg1); - tem = fold_binary_loc (loc, BIT_AND_EXPR, type, shift, mask); - if (tem) - return tem; - } - return NULL_TREE; case MIN_EXPR: diff --git a/gcc/match.pd b/gcc/match.pd index 641148652b2..5e8fd32ed22 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -230,7 +230,14 @@ along with GCC; see the file COPYING3. If not see /* (X % Y) % Y is just X % Y. */ (simplify (mod (mod@2 @0 @1) @1) - @2)) + @2) + /* From extract_muldiv_1: (X * C1) % C2 is zero if C1 is a multiple of C2. */ + (simplify + (mod (mult @0 INTEGER_CST@1) INTEGER_CST@2) + (if (ANY_INTEGRAL_TYPE_P (type) + && TYPE_OVERFLOW_UNDEFINED (type) + && wi::multiple_of_p (@1, @2, TYPE_SIGN (type))) + { build_zero_cst (type); }))) /* X % -C is the same as X % C. */ (simplify @@ -992,6 +999,16 @@ along with GCC; see the file COPYING3. If not see (if (shift_type == TREE_TYPE (@3)) (bit_and @4 { newmaskt; })))))))))))) +/* Fold (X & C2) << C1 into (X << C1) & (C2 << C1) + (X & C2) >> C1 into (X >> C1) & (C2 >> C1). */ +(for shift (lshift rshift) + (simplify + (shift (convert? (bit_and @0 INTEGER_CST@2)) INTEGER_CST@1) + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with { tree mask = int_const_binop (shift, fold_convert (type, @2), @1); } + (bit_and (shift (convert @0) @1) { mask; }))))) + + /* Simplifications of conversions. */ /* Basic strip-useless-type-conversions / strip_nops. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 72df6adee18..d9fa97a3f65 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-07-07 Richard Biener + + * gcc.dg/vect/vect-over-widen-3-big-array.c: Adjust. + 2015-07-07 Andrew Bennett * gcc.target/mips/call-1.c: Allow testcase to match the jrc instruction. diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-3-big-array.c b/gcc/testsuite/gcc.dg/vect/vect-over-widen-3-big-array.c index f5afc44c115..1ca312829a7 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-3-big-array.c +++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-3-big-array.c @@ -58,6 +58,6 @@ int main (void) return 0; } -/* { dg-final { scan-tree-dump-times "vect_recog_over_widening_pattern: detected" 1 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vect_recog_over_widening_pattern: detected" 2 "vect" } } */ /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */