aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2022-01-12 13:31:08 -0500
committerAndrew MacLeod <amacleod@redhat.com>2022-01-13 13:51:30 -0500
commit49d5fb4feee831868d80fff4d024c271911c92ca (patch)
tree3ddef029955525380150636e13c8fb8252fb8e8f
parent27e4260166950b784fe270ba4f0cae9a66faf1c4 (diff)
downloadgcc-49d5fb4feee831868d80fff4d024c271911c92ca.zip
gcc-49d5fb4feee831868d80fff4d024c271911c92ca.tar.gz
gcc-49d5fb4feee831868d80fff4d024c271911c92ca.tar.bz2
Allow more precision when querying from fold_const.
fold_const::expr_not_equal_to queries for a current range, but still uses the old value_range class. This is causing it to miss opportunities when ranger can provide something better. PR tree-optimization/83072 PR tree-optimization/83073 PR tree-optimization/97909 gcc/ * fold-const.c (expr_not_equal_to): Use a multi-range class. gcc/testsuite/ * gcc.dg/pr83072-2.c: New. * gcc.dg/pr83073.c: New.
-rw-r--r--gcc/fold-const.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr83072-2.c18
-rw-r--r--gcc/testsuite/gcc.dg/pr83073.c10
3 files changed, 29 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 397fa9a..cd540e1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10734,7 +10734,7 @@ tree_expr_nonzero_p (tree t)
bool
expr_not_equal_to (tree t, const wide_int &w)
{
- value_range vr;
+ int_range_max vr;
switch (TREE_CODE (t))
{
case INTEGER_CST:
diff --git a/gcc/testsuite/gcc.dg/pr83072-2.c b/gcc/testsuite/gcc.dg/pr83072-2.c
new file mode 100644
index 0000000..f495f25
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83072-2.c
@@ -0,0 +1,18 @@
+/* { dg-do compile} */
+/* { dg-options "-O2 -fdump-tree-evrp-details" } */
+
+int f1(int a, int b, int c){
+ if(c==0)__builtin_unreachable();
+ a *= c;
+ b *= c;
+ return a == b;
+}
+
+int f2(int a, int b, int c){
+ c |= 1;
+ a *= c;
+ b *= c;
+ return a == b;
+}
+
+/* { dg-final { scan-tree-dump-times "gimple_simplified to" 2 "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/pr83073.c b/gcc/testsuite/gcc.dg/pr83073.c
new file mode 100644
index 0000000..1168ae82
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83073.c
@@ -0,0 +1,10 @@
+/* { dg-do compile} */
+/* { dg-options "-O2 -fdump-tree-evrp-details -fno-tree-fre -fno-tree-ccp -fno-tree-forwprop" } */
+
+int f(int x)
+{
+ x = x|1;
+ return x & 1;
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to.* = 1" "evrp" } } */