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 rtx_equal_p and similar predicates on ASM_OPERANDS/ASM_INPUT (PR rtl-optimization/46865)


Hi!

The last operand of ASM_OPERANDS and ASM_INPUT is a RTL locator,
for which we unfortunately don't guarantee uniqueness.  One has
to call locator_eq to actually compare them.
On the testcases below, without -save-temps the locators are equal
while without them some other location_t got a locator in between.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

For 4.7 I guess it would be better to invent a new RTL format letter
and use it for the locators, but guess that would be too invasive now in
stage3.

2010-12-09  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/46865
	* rtl.c (rtx_equal_p_cb, rtx_equal_p): For last operand of
	ASM_OPERANDS and ASM_INPUT if integers are different,
	call locator_eq.
	* jump.c (rtx_renumbered_equal_p): Likewise.

	* gcc.target/i386/pr46865-1.c: New test.
	* gcc.target/i386/pr46865-2.c: New test.

--- gcc/rtl.c.jj	2010-11-01 09:07:23.000000000 +0100
+++ gcc/rtl.c	2010-12-09 19:35:34.000000000 +0100
@@ -431,7 +431,15 @@ rtx_equal_p_cb (const_rtx x, const_rtx y
 	case 'n':
 	case 'i':
 	  if (XINT (x, i) != XINT (y, i))
-	    return 0;
+	    {
+#ifndef GENERATOR_FILE
+	      if (((code == ASM_OPERANDS && i == 6)
+		   || (code == ASM_INPUT && i == 1))
+		  && locator_eq (XINT (x, i), XINT (y, i)))
+		break;
+#endif
+	      return 0;
+	    }
 	  break;
 
 	case 'V':
@@ -555,7 +563,15 @@ rtx_equal_p (const_rtx x, const_rtx y)
 	case 'n':
 	case 'i':
 	  if (XINT (x, i) != XINT (y, i))
-	    return 0;
+	    {
+#ifndef GENERATOR_FILE
+	      if (((code == ASM_OPERANDS && i == 6)
+		   || (code == ASM_INPUT && i == 1))
+		  && locator_eq (XINT (x, i), XINT (y, i)))
+		break;
+#endif
+	      return 0;
+	    }
 	  break;
 
 	case 'V':
--- gcc/jump.c.jj	2010-12-02 11:51:31.000000000 +0100
+++ gcc/jump.c	2010-12-09 19:30:09.000000000 +0100
@@ -1727,7 +1727,13 @@ rtx_renumbered_equal_p (const_rtx x, con
 
 	case 'i':
 	  if (XINT (x, i) != XINT (y, i))
-	    return 0;
+	    {
+	      if (((code == ASM_OPERANDS && i == 6)
+		   || (code == ASM_INPUT && i == 1))
+		  && locator_eq (XINT (x, i), XINT (y, i)))
+		break;
+	      return 0;
+	    }
 	  break;
 
 	case 't':
--- gcc/testsuite/gcc.target/i386/pr46865-1.c.jj	2010-12-09 19:58:10.000000000 +0100
+++ gcc/testsuite/gcc.target/i386/pr46865-1.c	2010-12-09 19:58:06.000000000 +0100
@@ -0,0 +1,31 @@
+/* PR rtl-optimization/46865 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern unsigned long f;
+
+#define m1(f)							\
+  if (f & 1)							\
+    asm volatile ("nop /* asmnop */\n");			\
+  else								\
+    asm volatile ("nop /* asmnop */\n");
+
+#define m2(f)							\
+  if (f & 1)							\
+    asm volatile ("nop /* asmnop */\n" : : "i" (6) : "cx");	\
+  else								\
+    asm volatile ("nop /* asmnop */\n" : : "i" (6) : "cx");
+
+void
+foo (void)
+{
+  m1 (f);
+}
+
+void
+bar (void)
+{
+  m2 (f);
+}
+
+/* { dg-final { scan-assembler-times "asmnop" 2 } } */
--- gcc/testsuite/gcc.target/i386/pr46865-2.c.jj	2010-12-09 19:58:13.000000000 +0100
+++ gcc/testsuite/gcc.target/i386/pr46865-2.c	2010-12-09 19:57:40.000000000 +0100
@@ -0,0 +1,32 @@
+/* PR rtl-optimization/46865 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -save-temps" } */
+
+extern unsigned long f;
+
+#define m1(f)							\
+  if (f & 1)							\
+    asm volatile ("nop /* asmnop */\n");			\
+  else								\
+    asm volatile ("nop /* asmnop */\n");
+
+#define m2(f)							\
+  if (f & 1)							\
+    asm volatile ("nop /* asmnop */\n" : : "i" (6) : "cx");	\
+  else								\
+    asm volatile ("nop /* asmnop */\n" : : "i" (6) : "cx");
+
+void
+foo (void)
+{
+  m1 (f);
+}
+
+void
+bar (void)
+{
+  m2 (f);
+}
+
+/* { dg-final { scan-assembler-times "asmnop" 2 } } */
+/* { dg-final { cleanup-saved-temps } } */

	Jakub


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