tree-optimization/99473 - more cselim
authorRichard Biener <rguenther@suse.de>
Tue, 9 Mar 2021 08:29:29 +0000 (09:29 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 26 Apr 2021 08:10:06 +0000 (10:10 +0200)
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

2021-03-09  Richard Biener  <rguenther@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 [new file with mode: 0644]
gcc/tree-ssa-phiopt.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 (file)
index 0000000..a9fd542
--- /dev/null
@@ -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" } } */
index aa48f44..13e5c49 100644 (file)
@@ -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;