* [PATCH] IOR with nonzero, range cannot contain 0.
@ 2020-11-17 17:01 Andrew MacLeod
0 siblings, 0 replies; only message in thread
From: Andrew MacLeod @ 2020-11-17 17:01 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 288 bytes --]
PR 83072 mentions that we have lost the ability to recognize that when
we see
c |= 1;
c cannot be zero. We can at least put it back for multi-ranges. Added
a new testcase to make sure EVRP is tracking it.
bootstrapped on x86_64-pc-linux-gnu, no regressions. pushed.
Andrew
[-- Attachment #2: nz.diff --]
[-- Type: text/x-patch, Size: 1457 bytes --]
commit a5f9c27bfc4417224e332392bb81a2d733b2b5bf
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Tue Nov 17 10:04:38 2020 -0500
IOR with nonzero, range cannot contain 0.
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.
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index b746aadb603..d0adc95527a 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -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
index 00000000000..3bed8d89013
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83072.c
@@ -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" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-17 17:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 17:01 [PATCH] IOR with nonzero, range cannot contain 0 Andrew MacLeod
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).