From: Richard Biener Date: Tue, 9 Mar 2021 08:29:29 +0000 (+0100) Subject: tree-optimization/99473 - more cselim X-Git-Tag: basepoints/gcc-13~8199 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=577d05fc914338cd7ddc254f3bee4532331f5c13;p=thirdparty%2Fgcc.git tree-optimization/99473 - more cselim 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 PR tree-optimization/99473 * tree-ssa-phiopt.c (cond_store_replacement): Handle all stores. * gcc.dg/tree-ssa/pr99473-1.c: New testcase. --- 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 000000000000..a9fd54276942 --- /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 aa48f447d23c..13e5c4971d2c 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;