Patchwork Another combiner 4 insn issue fix (PR middle-end/46637)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 24, 2010, 9:41 p.m.
Message ID <20101124214105.GF29412@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/72949/
State New
Headers show

Comments

Jakub Jelinek - Nov. 24, 2010, 9:41 p.m.
Hi!

On this testcase (both x86_64-linux and i686-linux)
i0dest_in_i0src is 1, and so is i0_feeds_i1_n and i1_feeds_i2_n,
but i1dest_in_i1src is 0 and i0_feeds_i2_n is 0 as well.
Nevertheless, we need to call subst with 1 as last argument
when substing i2src for i2dest, otherwise we get similar sharing
problems to what happens when i0dest_in_i0src i0 feeds directly i2
instead of indirectly.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-11-24  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/46637
	* combine.c (try_combine): When substing i2dest for i2src, pass
	1 as last argument even if
	i0_feeds_i1_n && i1_feeds_i2_n && i0dest_in_i0src.

	* gcc.c-torture/compile/pr46637.c: New test.


	Jakub
Eric Botcazou - Nov. 25, 2010, 11:15 a.m.
> 2010-11-24  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/46637
> 	* combine.c (try_combine): When substing i2dest for i2src, pass
> 	1 as last argument even if
> 	i0_feeds_i1_n && i1_feeds_i2_n && i0dest_in_i0src.
>
> 	* gcc.c-torture/compile/pr46637.c: New test.

OK, but the comment also needs to be adjusted, for example:

	later.  Likewise if I0 feeds into I2, either directly or indirectly
	through I1, and I0DEST is in I0SRC.  */

Patch

--- gcc/combine.c.jj	2010-11-19 20:56:55.000000000 +0100
+++ gcc/combine.c	2010-11-24 14:29:39.000000000 +0100
@@ -3099,7 +3099,8 @@  try_combine (rtx i3, rtx i2, rtx i1, rtx
 	 later.  Likewise if I0 feeds into I2 and I0DEST is in I0SRC.  */
       newpat = subst (PATTERN (i3), i2dest, i2src, 0,
 		      (i1_feeds_i2_n && i1dest_in_i1src)
-		      || (i0_feeds_i2_n && i0dest_in_i0src));
+		      || ((i0_feeds_i2_n || (i0_feeds_i1_n && i1_feeds_i2_n))
+			  && i0dest_in_i0src));
       substed_i2 = 1;
 
       /* Record whether I2's body now appears within I3's body.  */
--- gcc/testsuite/gcc.c-torture/compile/pr46637.c.jj	2010-11-24 14:38:02.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr46637.c	2010-11-24 14:37:52.000000000 +0100
@@ -0,0 +1,11 @@ 
+/* PR middle-end/46637 */
+
+struct S { int s[5]; } *p;
+
+void
+foo (long x)
+{
+  long a = x == 1 ? 4L : 1L;
+  asm ("" : "+m" (p->s[a]));
+  p->s[0]++;
+}