@@ -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 ())
{
new file mode 100644
@@ -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" } }