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]

[PATCH] Fix combine handling of STRICT_LOW_PART (PR rtl-optimization/17825)


Hi!

In the testcase below, both 3.4.x and 4.0 "optimize"
(strict_low_part (subreg:HI (reg:SI xxx) 0))
into (strict_low_part (reg:HI xxx)).
But rtl.texi has:
@cindex @code{subreg}, in @code{strict_low_part}
@item (strict_low_part (subreg:@var{m} (reg:@var{n} @var{r}) 0))
This expression code is used in only one context: as the destination operand of a
@code{set} expression.  In addition, the operand of this expression
must be a non-paradoxical @code{subreg} expression.

and clearly many places in the compiler rely on the documented
rule that STRICT_LOW_PART's argument is a (non-paradoxical) SUBREG of a REG.

The hunk below in subst.c therefore has never been true if code ==
STRICT_LOW_PART, but IMHO we don't want to optimize the SUBREG
inside of STRICT_LOW_PART out, as then we break the documented rule.

Ok to commit if testing succeeds? gcc-3_4-branch as well?

2004-11-19  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/17825
	* combine.c (subst): Ignore STRICT_LOW_PART no matter if REG_P (new)
	or not.

	* gcc.c-torture/compile/20041119-1.c: New test.

--- gcc/combine.c.jj	2004-10-28 15:09:05.000000000 +0200
+++ gcc/combine.c	2004-11-19 15:15:01.031574634 +0100
@@ -3556,10 +3556,10 @@ subst (rtx x, rtx from, rtx to, int in_d
 	      /* If this is a register being set, ignore it.  */
 	      new = XEXP (x, i);
 	      if (in_dest
-		  && (code == SUBREG || code == STRICT_LOW_PART
-		      || code == ZERO_EXTRACT)
 		  && i == 0
-		  && REG_P (new))
+		  && (((code == SUBREG || code == ZERO_EXTRACT)
+		       && REG_P (new))
+		      || code == STRICT_LOW_PART))
 		;
 
 	      else if (COMBINE_RTX_EQUAL_P (XEXP (x, i), from))
--- gcc/testsuite/gcc.c-torture/compile/20041119-1.c.jj	2004-11-19 15:32:36.679393511 +0100
+++ gcc/testsuite/gcc.c-torture/compile/20041119-1.c	2004-11-19 15:31:05.000000000 +0100
@@ -0,0 +1,30 @@
+/* PR rtl-optimization/17825 */
+#ifdef __i386__
+register unsigned int reg __asm ("esi");
+#elif defined __x86_64__
+register unsigned int reg __asm ("r14");
+#else
+unsigned int reg;
+#endif
+
+struct S
+{
+  unsigned int h[8];
+} *b;
+unsigned int c;
+void foo (int);
+
+void
+bar (void)
+{
+  unsigned int j, k, l, m;
+
+  j = (reg & 0xffff) | ((b->h[2] & 0xffff) << 16);
+  k = c & 0xffff;
+  if (k == 0)
+    foo (0);
+  l = (j / k) & 0xffff;
+  m = (j % k) & 0xffff;
+  reg = (reg & 0xffff0000) | l;
+  b->h[2] = (b->h[2] & 0xffff0000) | m;
+}

	Jakub


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