[PATCH] Fix PR45860
Richard Guenther
rguenther@suse.de
Wed Oct 20 12:24:00 GMT 2010
Conditional store-elimination is confused when a non-register typed
constant is stored (such as any STRING_CST).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2010-10-20 Richard Guenther <rguenther@suse.de>
PR tree-optimization/45860
* tree-ssa-phiopt.c (cond_store_replacement): Do not do
conditional store replacement for non-register type stores.
* gcc.dg/torture/pr45860.c: New testcase.
Index: gcc/tree-ssa-phiopt.c
===================================================================
*** gcc/tree-ssa-phiopt.c (revision 165712)
--- gcc/tree-ssa-phiopt.c (working copy)
*************** cond_store_replacement (basic_block midd
*** 1204,1213 ****
|| TREE_CODE (TREE_OPERAND (lhs, 0)) != SSA_NAME)
return false;
! /* RHS is either a single SSA_NAME or a constant. */
code = gimple_assign_rhs_code (assign);
if (get_gimple_rhs_class (code) != GIMPLE_SINGLE_RHS
! || (code != SSA_NAME && !is_gimple_min_invariant (rhs)))
return false;
/* Prove that we can move the store down. We could also check
TREE_THIS_NOTRAP here, but in that case we also could move stores,
--- 1204,1214 ----
|| TREE_CODE (TREE_OPERAND (lhs, 0)) != SSA_NAME)
return false;
! /* RHS is either a single SSA_NAME or a constant of register type. */
code = gimple_assign_rhs_code (assign);
if (get_gimple_rhs_class (code) != GIMPLE_SINGLE_RHS
! || (code != SSA_NAME && !is_gimple_min_invariant (rhs))
! || !is_gimple_reg_type (TREE_TYPE (lhs)))
return false;
/* Prove that we can move the store down. We could also check
TREE_THIS_NOTRAP here, but in that case we also could move stores,
*************** cond_store_replacement (basic_block midd
*** 1217,1224 ****
/* Now we've checked the constraints, so do the transformation:
1) Remove the single store. */
- mark_symbols_for_renaming (assign);
gsi = gsi_for_stmt (assign);
gsi_remove (&gsi, true);
/* 2) Create a temporary where we can store the old content
--- 1218,1225 ----
/* Now we've checked the constraints, so do the transformation:
1) Remove the single store. */
gsi = gsi_for_stmt (assign);
+ unlink_stmt_vdef (assign);
gsi_remove (&gsi, true);
/* 2) Create a temporary where we can store the old content
*************** cond_store_replacement (basic_block midd
*** 1237,1243 ****
name = make_ssa_name (condstoretemp, new_stmt);
gimple_assign_set_lhs (new_stmt, name);
gimple_set_location (new_stmt, locus);
- mark_symbols_for_renaming (new_stmt);
gsi_insert_on_edge (e1, new_stmt);
/* 4) Create a PHI node at the join block, with one argument
--- 1238,1243 ----
*************** cond_store_replacement (basic_block midd
*** 1249,1255 ****
lhs = unshare_expr (lhs);
new_stmt = gimple_build_assign (lhs, PHI_RESULT (newphi));
- mark_symbols_for_renaming (new_stmt);
/* 5) Insert that PHI node. */
gsi = gsi_after_labels (join_bb);
--- 1249,1254 ----
Index: gcc/testsuite/gcc.dg/torture/pr45860.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr45860.c (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr45860.c (revision 0)
***************
*** 0 ****
--- 1,11 ----
+ /* { dg-do compile } */
+
+ void
+ foo (char *str, int i)
+ {
+ static const char text[] = "";
+ str[i] = 0;
+ if (i & 1)
+ __builtin_strcpy (str + i, text);
+ }
+
More information about the Gcc-patches
mailing list