diff options
author | Paolo Bonzini <bonzini@gcc.gnu.org> | 2016-12-05 13:19:34 +0000 |
---|---|---|
committer | Paolo Bonzini <bonzini@gcc.gnu.org> | 2016-12-05 13:19:34 +0000 |
commit | 519e0faa00bda70c9ffd66b7e7a6011c5e742d2b (patch) | |
tree | b2b3238a915ab7d938a1ee24f4bf5be5561f10a5 /gcc/match.pd | |
parent | d0ea9f0aa270f9791df42eb409e90c718575ad9a (diff) | |
download | gcc-519e0faa00bda70c9ffd66b7e7a6011c5e742d2b.zip gcc-519e0faa00bda70c9ffd66b7e7a6011c5e742d2b.tar.gz gcc-519e0faa00bda70c9ffd66b7e7a6011c5e742d2b.tar.bz2 |
match.pd: Simplify X ? C : 0 where C is a power of 2 and X tests a single bit.
gcc:
* match.pd: Simplify X ? C : 0 where C is a power of 2 and
X tests a single bit.
gcc/testsuite:
* gcc.dg/fold-and-lshift.c, gcc.dg/fold-and-rshift-1.c,
gcc.dg/fold-and-rshift-2.c: New testcases.
From-SVN: r243255
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index dbb9103..1fe003b 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2737,6 +2737,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (bit_and@2 @0 integer_pow2p@1) @1) (icmp @2 { build_zero_cst (TREE_TYPE (@0)); }))) +/* If we have (A & C) != 0 ? D : 0 where C and D are powers of 2, + convert this into a shift followed by ANDing with D. */ +(simplify + (cond + (ne (bit_and @0 integer_pow2p@1) integer_zerop) + integer_pow2p@2 integer_zerop) + (with { + int shift = wi::exact_log2 (@2) - wi::exact_log2 (@1); + } + (if (shift > 0) + (bit_and + (lshift (convert @0) { build_int_cst (integer_type_node, shift); }) @2) + (bit_and + (convert (rshift @0 { build_int_cst (integer_type_node, -shift); })) @2)))) + /* If we have (A & C) != 0 where C is the sign bit of A, convert this into A < 0. Similarly for (A & C) == 0 into A >= 0. */ (for cmp (eq ne) @@ -2751,6 +2766,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { tree stype = signed_type_for (TREE_TYPE (@0)); } (ncmp (convert:stype @0) { build_zero_cst (stype); }))))) +/* If we have A < 0 ? C : 0 where C is a power of 2, convert + this into a right shift followed by ANDing with C. */ +(simplify + (cond + (lt @0 integer_zerop) + integer_pow2p@1 integer_zerop) + (with { + int shift = element_precision (@0) - wi::exact_log2 (@1) - 1; + } + (bit_and + (convert (rshift @0 { build_int_cst (integer_type_node, shift); })) + @1))) + /* When the addresses are not directly of decls compare base and offset. This implements some remaining parts of fold_comparison address comparisons but still no complete part of it. Still it is good |