This fixes the pre-condition on cselim to include all references
and decls when they end up as auto-var.

Bootstrapped/tested on x86_64-linux, pushed to trunk.

2021-03-09  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/99473
        * tree-ssa-phiopt.c (cond_store_replacement): Handle all
        stores.

        * gcc.dg/tree-ssa/pr99473-1.c: New testcase.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr99473-1.c | 14 ++++++++++++++
 gcc/tree-ssa-phiopt.c                     |  5 ++---
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr99473-1.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr99473-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr99473-1.c
new file mode 100644
index 00000000000..a9fd5427694
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr99473-1.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fallow-store-data-races -fdump-tree-cselim-details" } */
+
+void f (int*);
+
+void g3 (int i)
+{
+  int x = 0;
+  if (i)
+    x = i;
+  f (&x);
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement happened" 
"cselim" } } */
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index aa48f447d23..13e5c4971d2 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -2490,9 +2490,8 @@ cond_store_replacement (basic_block middle_bb, 
basic_block join_bb,
   locus = gimple_location (assign);
   lhs = gimple_assign_lhs (assign);
   rhs = gimple_assign_rhs1 (assign);
-  if ((TREE_CODE (lhs) != MEM_REF
-       && TREE_CODE (lhs) != ARRAY_REF
-       && TREE_CODE (lhs) != COMPONENT_REF)
+  if ((!REFERENCE_CLASS_P (lhs)
+       && !DECL_P (lhs))
       || !is_gimple_reg_type (TREE_TYPE (lhs)))
     return false;
 
-- 
2.26.2

Reply via email to