So when I wrote this code I limited the middle store to only
be a SSA name. This is too limited and we reject constants which the full
cselim can handle just fine. This extends the check to support gimple
min invariants too.
Instead of the check for ssa name, reject clobbers instead.
Changes since v1:
* v2: Change the checks to reject clobbers instead of checking
for min invariant/ssa names.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/127052
gcc/ChangeLog:
* tree-ssa-phiopt.cc (cond_store_replacement_limited): Reject clobbers
for the middle bb store. And Remove the check on ssa name for the rhs
of the middle bb store.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/cselim-6.c: New test.
* gcc.dg/tree-ssa/cselim-7.c: New test.
Signed-off-by: Andrea Pinski <[email protected]>
---
gcc/testsuite/gcc.dg/tree-ssa/cselim-6.c | 17 +++++++++++++++++
gcc/testsuite/gcc.dg/tree-ssa/cselim-7.c | 18 ++++++++++++++++++
gcc/tree-ssa-phiopt.cc | 6 +++---
3 files changed, 38 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cselim-6.c
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cselim-7.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cselim-6.c
b/gcc/testsuite/gcc.dg/tree-ssa/cselim-6.c
new file mode 100644
index 00000000000..54d1446ecd7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cselim-6.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-cselim -fdump-tree-phiopt1-details" } */
+/* PR tree-optimization/127052 */
+
+int *sink(int*);
+void f(int a, int c, int d, int *e)
+{
+ e = sink(&a);
+ a = d;
+ c = *e;
+ c += a;
+ if (c)
+ a = 0;
+ sink(&a);
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "phiopt1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cselim-7.c
b/gcc/testsuite/gcc.dg/tree-ssa/cselim-7.c
new file mode 100644
index 00000000000..8db89c24b56
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cselim-7.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-cselim -fdump-tree-phiopt1-details" } */
+/* PR tree-optimization/127052 */
+
+void sink(int*);
+
+int f(int b)
+{
+ int a;
+ sink(&a);
+ a = b;
+ if (a)
+ a = 0;
+ return a;
+}
+
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "phiopt1" } } */
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 6e17d21b58c..343cd159118 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3601,7 +3601,9 @@ cond_store_replacement_limited (basic_block middle_bb,
basic_block join_bb,
if (!store_middle
|| !gimple_assign_single_p (store_middle)
- || gimple_has_volatile_ops (store_middle))
+ || gimple_has_volatile_ops (store_middle)
+ // Rejects clobbers too.
+ || gimple_clobber_p (store_middle))
return false;
locus = gimple_location (store_middle);
@@ -3611,8 +3613,6 @@ cond_store_replacement_limited (basic_block middle_bb,
basic_block join_bb,
&& !DECL_P (lhs))
|| !is_gimple_reg_type (TREE_TYPE (lhs)))
return false;
- if (TREE_CODE (rhs) != SSA_NAME)
- return false;
/* Three cases that can be handled:
1) the lhs is stored to right before the condition.
--
2.43.0