gimple-fold.c (gimple_fold_builtin_memory_op): Make sure to fold the RHS to a constan...
authorRichard Biener <rguenther@suse.de>
Fri, 10 Jun 2016 11:44:47 +0000 (11:44 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 10 Jun 2016 11:44:47 +0000 (11:44 +0000)
2016-06-10  Richard Biener  <rguenther@suse.de>

* gimple-fold.c (gimple_fold_builtin_memory_op): Make sure
to fold the RHS to a constant if possible.

From-SVN: r237301

gcc/ChangeLog
gcc/gimple-fold.c

index 9cab3118d65d7580e00c8bb12b6ad5fe1dda9ea5..5038f751ae3465997399a53fe83ab51decd8305e 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-10  Richard Biener  <rguenther@suse.de>
+
+       * gimple-fold.c (gimple_fold_builtin_memory_op): Make sure
+       to fold the RHS to a constant if possible.
+
 2016-06-10  Thomas Schwinge  <thomas@codesourcery.com>
 
        PR middle-end/71373
index 600aa72f217185f17230d4bf774f2b66e7e5aa85..885367e911494a4a03bb24a532f5e73fecd7a1b1 100644 (file)
@@ -1020,14 +1020,20 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
       gimple *new_stmt;
       if (is_gimple_reg_type (TREE_TYPE (srcvar)))
        {
-         new_stmt = gimple_build_assign (NULL_TREE, srcvar);
-         if (gimple_in_ssa_p (cfun))
-           srcvar = make_ssa_name (TREE_TYPE (srcvar), new_stmt);
-         else
-           srcvar = create_tmp_reg (TREE_TYPE (srcvar));
-         gimple_assign_set_lhs (new_stmt, srcvar);
-         gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-         gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
+         tree tem = fold_const_aggregate_ref (srcvar);
+         if (tem)
+           srcvar = tem;
+         if (! is_gimple_min_invariant (srcvar))
+           {
+             new_stmt = gimple_build_assign (NULL_TREE, srcvar);
+             if (gimple_in_ssa_p (cfun))
+               srcvar = make_ssa_name (TREE_TYPE (srcvar), new_stmt);
+             else
+               srcvar = create_tmp_reg (TREE_TYPE (srcvar));
+             gimple_assign_set_lhs (new_stmt, srcvar);
+             gimple_set_vuse (new_stmt, gimple_vuse (stmt));
+             gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
+           }
        }
       new_stmt = gimple_build_assign (destvar, srcvar);
       gimple_set_vuse (new_stmt, gimple_vuse (stmt));