This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add VRP stmt folding to EVRP
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 18 May 2018 13:52:46 +0200 (CEST)
- Subject: [PATCH] Add VRP stmt folding to EVRP
While working on somehow re-ordering the first VRP pass after loop-header
copying I noticed that EVRP doesn't do VRP stmt simplifications. The
following adds this alongside the usual testsuite adjustments.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2018-05-18 Richard Biener <rguenther@suse.de>
* gimple-ssa-evrp.c (class evrp_folder): Add simplify_stmt_using_ranges
method.
(evrp_dom_walker::before_dom_children): Call it.
* gcc.dg/tree-ssa/pr21559.c: Adjust.
* gcc.dg/tree-ssa/pr45397.c: Likewise.
* gcc.dg/tree-ssa/pr61839_1.c: Likewise.
* gcc.dg/tree-ssa/pr61839_2.c: Likewise.
* gcc.dg/tree-ssa/pr61839_4.c: Likewise.
* gcc.dg/tree-ssa/vrp17.c: Likewise.
* gcc.dg/tree-ssa/vrp18.c: Likewise.
* gcc.dg/tree-ssa/vrp23.c: Likewise.
* gcc.dg/tree-ssa/vrp24.c: Likewise.
* gcc.dg/tree-ssa/vrp58.c: Likewise.
* gcc.dg/vrp-min-max-1.c: Likewise.
* gcc.dg/vrp-min-max-3.c: New testcase.
diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index c9bbf09a406..b9a054fd2ee 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -47,6 +47,8 @@ class evrp_folder : public substitute_and_fold_engine
public:
tree get_value (tree) FINAL OVERRIDE;
evrp_folder (class vr_values *vr_values_) : vr_values (vr_values_) { }
+ bool simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
+ { return vr_values->simplify_stmt_using_ranges (gsi); }
class vr_values *vr_values;
private:
@@ -180,6 +182,12 @@ evrp_dom_walker::before_dom_children (basic_block bb)
update_stmt (stmt);
did_replace = true;
}
+ if (evrp_folder.simplify_stmt_using_ranges (&gsi))
+ {
+ stmt = gsi_stmt (gsi);
+ update_stmt (stmt);
+ did_replace = true;
+ }
if (did_replace)
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21559.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21559.c
index 0906351350e..b4065668ff8 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr21559.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21559.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fdump-tree-evrp-details -fdump-tree-vrp1-details" } */
static int blocksize = 4096;
@@ -33,7 +33,7 @@ void foo (void)
/* First, we should simplify the bits < 0 test within the loop. */
-/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "evrp" } } */
/* Second, we should thread the edge out of the loop via the break
statement. We also realize that the final bytes == 0 test is useless,
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr45397.c b/gcc/testsuite/gcc.dg/tree-ssa/pr45397.c
index 18c7f0bcecc..af75a75b1e2 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr45397.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr45397.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt1" } */
+/* { dg-options "-O2 -fdump-tree-phiopt1 -fdump-tree-evrp" } */
int foo_add (const unsigned char *tmp, int i, int val)
{
@@ -18,6 +18,7 @@ int foo_mul (const unsigned char *tmp, int i, int val)
/* All cases should end up using min/max for the saturated operations and
have no control flow. */
+/* { dg-final { scan-tree-dump-not " & 255;" "evrp" } } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */
/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
/* { dg-final { scan-tree-dump-not "if " "phiopt1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_1.c
index 9f8168a81f2..d44c7dc1882 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_1.c
@@ -1,6 +1,6 @@
/* PR tree-optimization/61839. */
/* { dg-do run } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-vrp1 -fdisable-tree-evrp -fdump-tree-optimized" } */
/* { dg-require-effective-target int32plus } */
__attribute__ ((noinline))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
index 638189e66e5..cfec54de991 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
@@ -51,4 +51,4 @@ int bar2 ()
/* Dont optimize 972195717 % 0 in function bar. */
/* { dg-final { scan-tree-dump-times "972195717 % " 1 "evrp" } } */
/* May optimize in function bar2, but EVRP doesn't perform this yet. */
-/* { dg-final { scan-tree-dump-times "972195715 % " 0 "evrp" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-times "972195715 % " 0 "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_4.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_4.c
index 5c026c89c7d..a346912d121 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_4.c
@@ -1,6 +1,6 @@
/* PR tree-optimization/61839. */
/* { dg-do run } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-vrp1 -fdisable-tree-evrp -fdump-tree-optimized" } */
/* { dg-require-effective-target int32plus } */
__attribute__ ((noinline))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp17.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp17.c
index 4f121030186..b8470e7a3db 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp17.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp17.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
extern void abort (void) __attribute__ ((__noreturn__));
union tree_node;
@@ -27,5 +27,5 @@ gimplify_for_stmt (tree stmt)
abort ();
}
-/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp18.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp18.c
index 008eebb25e4..d7ab3f69f37 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp18.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp18.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
static int blocksize = 4096;
@@ -30,4 +30,4 @@ void foo (void)
eof_reached = 1;
}
-/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp23.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp23.c
index ae68c090f77..6ac8d55600d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp23.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp23.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-evrp-details" } */
void aa (void);
void aos (void);
@@ -45,5 +45,5 @@ L8:
/* The n_sets > 0 test can be simplified into n_sets == 1 since the
only way to reach the test is when n_sets <= 1, and the only value
which satisfies both conditions is n_sets == 1. */
-/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp24.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp24.c
index ed49e25f87a..dfe44b30649 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp24.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp24.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-evrp-details -fdump-tree-optimized" } */
struct rtx_def;
@@ -88,6 +88,6 @@ L7:
n_sets can only have the values [0, 1] as it's the result of a
boolean operation. */
-/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 2 "evrp" } } */
/* { dg-final { scan-tree-dump-times "if " 4 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp58.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp58.c
index 5b44ae2cfd1..b64a2df8f33 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp58.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp58.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
long long
foo (long long a, signed char b, signed char c)
@@ -8,5 +8,5 @@ foo (long long a, signed char b, signed char c)
return a + (short)bc;
}
-/* { dg-final { scan-tree-dump "Folded into" "vrp1" { target int32plus } } } */
-/* { dg-final { scan-tree-dump "Folding statement: _\[0-9\]\* = \\(long long int\\) bc_\[0-9\]\*;" "vrp1" { target int16 } } } */
+/* EVRP should remove the truncation to short, keeping (long long)bc. */
+/* { dg-final { scan-tree-dump-not "short" "cddce1" { target int32plus } } } */
diff --git a/gcc/testsuite/gcc.dg/vrp-min-max-1.c b/gcc/testsuite/gcc.dg/vrp-min-max-1.c
index 270f2bbb436..b9c8379c832 100644
--- a/gcc/testsuite/gcc.dg/vrp-min-max-1.c
+++ b/gcc/testsuite/gcc.dg/vrp-min-max-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-mergephi2" } */
+/* { dg-options "-O2 -fdump-tree-vrp1 -fdisable-tree-evrp -fdump-tree-mergephi2" } */
int bar (void);
diff --git a/gcc/testsuite/gcc.dg/vrp-min-max-3.c b/gcc/testsuite/gcc.dg/vrp-min-max-3.c
new file mode 100644
index 00000000000..1fffee7bbd9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vrp-min-max-3.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp -fdump-tree-fre1" } */
+
+int bar (void);
+
+int foo1 (int x, int y)
+{
+ if (y < 10) return bar ();
+ if (x > 9) return bar ();
+
+ return x < y ? x : y;
+}
+
+int foo2 (int x, int y)
+{
+ if (y < 10) return bar ();
+ if (x > 9) return bar ();
+
+ return x > y ? x : y;
+}
+
+/* We expect to optimiz min/max in EVRP */
+
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "fre1" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "fre1" } } */
+/* { dg-final { scan-tree-dump-not "MIN_EXPR" "evrp" } } */
+/* { dg-final { scan-tree-dump-not "MAX_EXPR" "evrp" } } */