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.
--- /dev/null
+/* { 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" } } */
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;