IOR with nonzero, range cannot contain 0.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 17 Nov 2020 15:04:38 +0000 (10:04 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Tue, 17 Nov 2020 16:58:07 +0000 (11:58 -0500)
Remove zero from IOR ranges with non-zero masks.

gcc/
PR tree-optimization/83072
* range-op.cc (wi_optimize_and_or): Remove zero from IOR range when
mask is non-zero.
gcc/testsuite/
* gcc.dg/pr83072.c: New.

gcc/range-op.cc
gcc/testsuite/gcc.dg/pr83072.c [new file with mode: 0644]

index b746aadb603172159cbeb2a35c14c2e98066f05e..d0adc95527a5ac2c532fe22ea9cfa912e6153e9f 100644 (file)
@@ -2163,6 +2163,14 @@ wi_optimize_and_or (irange &r,
   else
     gcc_unreachable ();
   value_range_with_overflow (r, type, res_lb, res_ub);
+
+  // Furthermore, if the mask is non-zero, an IOR cannot contain zero.
+  if (code == BIT_IOR_EXPR && wi::ne_p (mask, 0))
+    {
+      int_range<2> tmp;
+      tmp.set_nonzero (type);
+      r.intersect (tmp);
+    }
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr83072.c b/gcc/testsuite/gcc.dg/pr83072.c
new file mode 100644 (file)
index 0000000..3bed8d8
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre" } */
+
+void kill (void);
+
+int f(int c){
+  c |= 1;
+  if (c == 0)
+    kill ();
+
+  return c;
+}
+
+/* { dg-final { scan-tree-dump-not "kill" "evrp" } }  */