public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fold RHS when open-coding memcpy
@ 2016-06-10 11:41 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2016-06-10 11:41 UTC (permalink / raw)
  To: gcc-patches


I noticed that we fail to fold the source to a constant if possible.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

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.

Index: gcc/gimple-fold.c
===================================================================
*** gcc/gimple-fold.c	(revision 237286)
--- gcc/gimple-fold.c	(working copy)
*************** gimple_fold_builtin_memory_op (gimple_st
*** 1020,1033 ****
        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);
  	}
        new_stmt = gimple_build_assign (destvar, srcvar);
        gimple_set_vuse (new_stmt, gimple_vuse (stmt));
--- 1020,1039 ----
        gimple *new_stmt;
        if (is_gimple_reg_type (TREE_TYPE (srcvar)))
  	{
! 	  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));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-10 11:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10 11:41 [PATCH] Fold RHS when open-coding memcpy Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).