PR tree-optimization/107043 gcc/ChangeLog:
* range-op.cc (operator_bitwise_and::op1_range): Update bitmask. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107043.c: New test. --- gcc/range-op.cc | 8 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr107043.c | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107043.c diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 56e80c9f3ae..6b5d4f2accd 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -3463,6 +3463,14 @@ operator_bitwise_and::op1_range (irange &r, tree type, if (r.undefined_p ()) set_nonzero_range_from_mask (r, type, lhs); + // For MASK == op1 & MASK, all the bits in MASK must be set in op1. + wide_int mask; + if (lhs == op2 && lhs.singleton_p (mask)) + { + r.update_bitmask (irange_bitmask (mask, ~mask)); + return true; + } + // For 0 = op1 & MASK, op1 is ~MASK. if (lhs.zero_p () && op2.singleton_p ()) { diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c new file mode 100644 index 00000000000..af5df225746 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c @@ -0,0 +1,22 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp" } + +int g0(int n) +{ + int n1 = n & 0x8000; + if (n1 == 0) + return 1; + // n1 will be 0x8000 here. + return (n1 >> 15) & 0x1; +} + +int g1(int n) +{ + int n1 = n & 0x8000; + if (n1 == 0) + return 1; + // n>>15 will be xxxxxx1 here. + return (n >> 15) & 0x1; +} + +// { dg-final { scan-tree-dump-times "return 1;" 2 "evrp" } } -- 2.40.1