public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][2/2] gimple-fold.c part for PR83141
@ 2017-11-27 15:41 Richard Biener
  2017-11-28 12:24 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2017-11-27 15:41 UTC (permalink / raw)
  To: gcc-patches


The following is the truly minimal fix for the middle-end issue
with SRA and memcpy folding interaction.  I've tried more variants
that "make sense" but as they all end up folding slightly more
memcpy calls than before we run into optimization testcase
regressions in places that look for __builtin_memcpy and do
not deal with aggregate copies as MEM[..] = MEM[..];

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

GCC 9 is the time we can try dealing with such fallout, it just
doesn't feel like the correct time to do now...

Richard.

2017-11-27  Richard Biener  <rguenther@suse.de>

	PR middle-end/83141
	* gimple-fold.c (gimple_fold_builtin_memory_op): For aggregate
	copies generated from memcpy use a character array as reference
	type.

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 255172)
+++ gcc/gimple-fold.c	(working copy)
@@ -1038,9 +1038,25 @@ gimple_fold_builtin_memory_op (gimple_st
 	      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);
+	      goto set_vop_and_replace;
 	    }
 	}
-      new_stmt = gimple_build_assign (destvar, srcvar);
+
+      /* We get an aggregate copy.  Use an unsigned char[] type to
+	 perform the copying to preserve padding and to avoid any issues
+	 with TREE_ADDRESSABLE types or float modes behavior on copying.  */
+      desttype = build_array_type_nelts (unsigned_char_type_node,
+					 tree_to_uhwi (len));
+      srctype = desttype;
+      if (src_align > TYPE_ALIGN (srctype))
+	srctype = build_aligned_type (srctype, src_align);
+      if (dest_align > TYPE_ALIGN (desttype))
+	desttype = build_aligned_type (desttype, dest_align);
+      new_stmt
+	= gimple_build_assign (fold_build2 (MEM_REF, desttype, dest, off0),
+			       fold_build2 (MEM_REF, srctype, src, off0));
+set_vop_and_replace:
       gimple_set_vuse (new_stmt, gimple_vuse (stmt));
       gimple_set_vdef (new_stmt, gimple_vdef (stmt));
       if (gimple_vdef (new_stmt)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][2/2] gimple-fold.c part for PR83141
  2017-11-27 15:41 [PATCH][2/2] gimple-fold.c part for PR83141 Richard Biener
@ 2017-11-28 12:24 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-11-28 12:24 UTC (permalink / raw)
  To: gcc-patches

On Mon, 27 Nov 2017, Richard Biener wrote:

> 
> The following is the truly minimal fix for the middle-end issue
> with SRA and memcpy folding interaction.  I've tried more variants
> that "make sense" but as they all end up folding slightly more
> memcpy calls than before we run into optimization testcase
> regressions in places that look for __builtin_memcpy and do
> not deal with aggregate copies as MEM[..] = MEM[..];
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> GCC 9 is the time we can try dealing with such fallout, it just
> doesn't feel like the correct time to do now...

Installed as follows, bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

2017-11-28  Richard Biener  <rguenther@suse.de>

	PR middle-end/83141
	* gimple-fold.c (gimple_fold_builtin_memory_op): For aggregate
	copies generated from memcpy use a character array as reference
	type.

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 255196)
+++ gcc/gimple-fold.c	(working copy)
@@ -1039,8 +1039,24 @@ gimple_fold_builtin_memory_op (gimple_st
 	      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
 	      gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
 	    }
+	  new_stmt = gimple_build_assign (destvar, srcvar);
+	  goto set_vop_and_replace;
 	}
-      new_stmt = gimple_build_assign (destvar, srcvar);
+
+      /* We get an aggregate copy.  Use an unsigned char[] type to
+	 perform the copying to preserve padding and to avoid any issues
+	 with TREE_ADDRESSABLE types or float modes behavior on copying.  */
+      desttype = build_array_type_nelts (unsigned_char_type_node,
+					 tree_to_uhwi (len));
+      srctype = desttype;
+      if (src_align > TYPE_ALIGN (srctype))
+	srctype = build_aligned_type (srctype, src_align);
+      if (dest_align > TYPE_ALIGN (desttype))
+	desttype = build_aligned_type (desttype, dest_align);
+      new_stmt
+	= gimple_build_assign (fold_build2 (MEM_REF, desttype, dest, off0),
+			       fold_build2 (MEM_REF, srctype, src, off0));
+set_vop_and_replace:
       gimple_set_vuse (new_stmt, gimple_vuse (stmt));
       gimple_set_vdef (new_stmt, gimple_vdef (stmt));
       if (gimple_vdef (new_stmt)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-28 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 15:41 [PATCH][2/2] gimple-fold.c part for PR83141 Richard Biener
2017-11-28 12:24 ` 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).