This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Avoid optimizing memory references with side effects in compare-elim.c



> On Jun 6, 2018, at 11:53 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> 
>> That simplifies the patch, which now looks like this.  Ok for trunk?
>> 
>> 	paul
>> 
>> gcc/ChangeLog:
>> 
>> 2018-06-05  Paul Koning  <ni1d@arrl.net>
>> 
>> 	* compare-elim.c (try_merge_compare): Don't merge compare if
>> 	address contains a side effect.
>> 	* gcc.c-torture/compile/20180605-1.c: New test case.
> 
> The patch is OK, but its ChangeLog is not. :-)  It does not modify one 
> function but two (try_merge_compare and try_eliminate_compare).  I would 
> suggest using "diff -up" to generate patches with more context.

Yes, sorry.  I normally use the subversion internal diff which doesn't do this.

Here is a corrected version.  Ok with this change?

	paul

gcc/ChangeLog:

2018-06-06  Paul Koning  <ni1d@arrl.net>

	* compare-elim.c (try_merge_compare): Don't merge compare if
	address contains a side effect.
	(try_eliminate_compare): Likewise.
	* gcc.c-torture/compile/20180605-1.c: New test case.

Index: compare-elim.c
===================================================================
--- compare-elim.c	(revision 261207)
+++ compare-elim.c	(working copy)
@@ -690,6 +690,13 @@ try_merge_compare (struct comparison *cm
     return false;
 
   rtx src = SET_SRC (set);
+
+  /* If the source uses addressing modes with side effects, we can't
+     do the merge because we'd end up with a PARALLEL that has two
+     instances of that side effect in it.  */
+  if (side_effects_p (src))
+    return false;
+
   rtx flags = maybe_select_cc_mode (cmp, src, CONST0_RTX (GET_MODE (src)));
   if (!flags)
     {
@@ -809,6 +816,12 @@ try_eliminate_compare (struct comparison
   else
     return false;
 
+  /* If the source uses addressing modes with side effects, we can't
+     do the merge because we'd end up with a PARALLEL that has two
+     instances of that side effect in it.  */
+  if (side_effects_p (cmp_src))
+    return false;
+
   /* Determine if we ought to use a different CC_MODE here.  */
   flags = maybe_select_cc_mode (cmp, cmp_src, in_b);
   if (flags == NULL)
Index: testsuite/gcc.c-torture/compile/20180605-1.c
===================================================================
--- testsuite/gcc.c-torture/compile/20180605-1.c	(nonexistent)
+++ testsuite/gcc.c-torture/compile/20180605-1.c	(working copy)
@@ -0,0 +1,9 @@
+void f (int *p, int n)
+{
+    int j = 0, k;
+    
+    for (int i = 0; i < n; i++)
+        if ((k = *p++) > 0)
+            j += k;
+    return j;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]