===================================================================
@@ -2602,10 +2602,20 @@ sra_modify_expr (tree *expr, gimple_stmt
if (!useless_type_conversion_p (type, access->type))
{
tree ref;
+ gimple stmt;
ref = build_ref_for_model (loc, access->base, access->offset, access,
NULL, false);
+ /* Reads and writes need at least the original access setup. */
+ if (access->grp_partial_lhs)
+ repl = force_gimple_operand_gsi (gsi, repl, true, NULL_TREE,
+ true, GSI_SAME_STMT);
+ stmt = gimple_build_assign (ref, repl);
+ gimple_set_location (stmt, loc);
+ gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
+
+ /* Writes read from the original access after the write has happened. */
if (write)
{
gimple stmt;
@@ -2617,17 +2627,6 @@ sra_modify_expr (tree *expr, gimple_stmt
gimple_set_location (stmt, loc);
gsi_insert_after (gsi, stmt, GSI_NEW_STMT);
}
- else
- {
- gimple stmt;
-
- if (access->grp_partial_lhs)
- repl = force_gimple_operand_gsi (gsi, repl, true, NULL_TREE,
- true, GSI_SAME_STMT);
- stmt = gimple_build_assign (ref, repl);
- gimple_set_location (stmt, loc);
- gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
- }
}
else
*expr = repl;