diff mbox

RFA: PR62208: const0_rtx used for vectors in simplify-rtx.c

Message ID 87tx4lxctu.fsf@googlemail.com
State New
Headers show

Commit Message

Richard Sandiford Sept. 6, 2014, 10:28 a.m. UTC
This PR is about a case where an XOR+EQ sequence can legitimately
be simplified.  The problem was that the sequence was operating on
vectors while the simplified version used a 0 CONST_INT (const0_rtx).

The code seems to have been like that for a long time but presumably
the bug has been latent until now.  I suppose normally we'd want
earlier optimisations to catch this.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
	PR rtl-optimization/62208
	* simplify-rtx.c (simplify_relational_operation_1): Use CONST0_RTX
	rather than const0_rtx in eq/ne-xor simplifications.

gcc/testsuite/
	* gcc.target/i386/pr62208.c: New test.

Comments

Richard Biener Sept. 6, 2014, 2:06 p.m. UTC | #1
On September 6, 2014 12:28:29 PM CEST, Richard Sandiford <rdsandiford@googlemail.com> wrote:
>This PR is about a case where an XOR+EQ sequence can legitimately
>be simplified.  The problem was that the sequence was operating on
>vectors while the simplified version used a 0 CONST_INT (const0_rtx).
>
>The code seems to have been like that for a long time but presumably
>the bug has been latent until now.  I suppose normally we'd want
>earlier optimisations to catch this.
>
>Tested on x86_64-linux-gnu.  OK to install?

OK.

Thanks,
Richard.

>Thanks,
>Richard
>
>
>gcc/
>	PR rtl-optimization/62208
>	* simplify-rtx.c (simplify_relational_operation_1): Use CONST0_RTX
>	rather than const0_rtx in eq/ne-xor simplifications.
>
>gcc/testsuite/
>	* gcc.target/i386/pr62208.c: New test.
>
>Index: gcc/simplify-rtx.c
>===================================================================
>--- gcc/simplify-rtx.c	2014-09-06 11:05:20.859563557 +0100
>+++ gcc/simplify-rtx.c	2014-09-06 11:05:20.935564244 +0100
>@@ -4480,16 +4480,16 @@ simplify_relational_operation_1 (enum rt
>       && op0code == XOR
>       && rtx_equal_p (XEXP (op0, 0), op1)
>       && !side_effects_p (XEXP (op0, 0)))
>-    return simplify_gen_relational (code, mode, cmp_mode,
>-				    XEXP (op0, 1), const0_rtx);
>+    return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0,
>1),
>+				    CONST0_RTX (mode));
> 
>   /* Likewise (eq/ne (xor x y) y) simplifies to (eq/ne x 0).  */
>   if ((code == EQ || code == NE)
>       && op0code == XOR
>       && rtx_equal_p (XEXP (op0, 1), op1)
>       && !side_effects_p (XEXP (op0, 1)))
>-    return simplify_gen_relational (code, mode, cmp_mode,
>-				    XEXP (op0, 0), const0_rtx);
>+    return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0,
>0),
>+				    CONST0_RTX (mode));
> 
>   /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)).  */
>   if ((code == EQ || code == NE)
>Index: gcc/testsuite/gcc.target/i386/pr62208.c
>===================================================================
>--- /dev/null	2014-09-03 21:33:59.721983712 +0100
>+++ gcc/testsuite/gcc.target/i386/pr62208.c	2014-09-06
>11:09:18.220708443 +0100
>@@ -0,0 +1,23 @@
>+/* { dg-options "-O3 -fwhole-program -march=x86-64" } */
>+
>+int *a;
>+unsigned int b;
>+
>+void fn2 ()
>+{
>+  int t[9];
>+  for (; b; b++)
>+    *a ^= (~t[b] != t[b]);
>+}
>+
>+int fn1 ()
>+{
>+  fn2 (); 
>+  return 0; 
>+}
>+
>+int main ()
>+{
>+  fn1 (); 
>+  return 0;
>+}
diff mbox

Patch

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	2014-09-06 11:05:20.859563557 +0100
+++ gcc/simplify-rtx.c	2014-09-06 11:05:20.935564244 +0100
@@ -4480,16 +4480,16 @@  simplify_relational_operation_1 (enum rt
       && op0code == XOR
       && rtx_equal_p (XEXP (op0, 0), op1)
       && !side_effects_p (XEXP (op0, 0)))
-    return simplify_gen_relational (code, mode, cmp_mode,
-				    XEXP (op0, 1), const0_rtx);
+    return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 1),
+				    CONST0_RTX (mode));
 
   /* Likewise (eq/ne (xor x y) y) simplifies to (eq/ne x 0).  */
   if ((code == EQ || code == NE)
       && op0code == XOR
       && rtx_equal_p (XEXP (op0, 1), op1)
       && !side_effects_p (XEXP (op0, 1)))
-    return simplify_gen_relational (code, mode, cmp_mode,
-				    XEXP (op0, 0), const0_rtx);
+    return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 0),
+				    CONST0_RTX (mode));
 
   /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)).  */
   if ((code == EQ || code == NE)
Index: gcc/testsuite/gcc.target/i386/pr62208.c
===================================================================
--- /dev/null	2014-09-03 21:33:59.721983712 +0100
+++ gcc/testsuite/gcc.target/i386/pr62208.c	2014-09-06 11:09:18.220708443 +0100
@@ -0,0 +1,23 @@ 
+/* { dg-options "-O3 -fwhole-program -march=x86-64" } */
+
+int *a;
+unsigned int b;
+
+void fn2 ()
+{
+  int t[9];
+  for (; b; b++)
+    *a ^= (~t[b] != t[b]);
+}
+
+int fn1 ()
+{
+  fn2 (); 
+  return 0; 
+}
+
+int main ()
+{
+  fn1 (); 
+  return 0;
+}