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] simplify-rtx.c: Fix rtl-optimization/27671 (Take 2).


Hi,

Attached is a revised patch to fix rtl-optimization/27671,
incorporating suggestions from Roger Sayle and Andrew Pinski.  The
original patch was posted at:

http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01034.html

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2006-05-21  Kazu Hirata  <kazu@codesourcery.com>

	PR rtl-optimization/27671
	* simplify-rtx.c (simplify_relational_operation_1): Fix
	simplifications of (eq/ne (xor x y) y) and
	(eq/ne (xor x y) x).

2006-05-21  Kazu Hirata  <kazu@codesourcery.com>

	PR rtl-optimization/27671
	* gcc.c-torture/execute/pr27671-1.c: New.
	* gcc.dg/pr27671-2.c: Likewise.

Index: simplify-rtx.c
===================================================================
*** simplify-rtx.c	(revision 113871)
--- simplify-rtx.c	(working copy)
***************
*** 3604,3621 ****
      return simplify_gen_relational (code, mode, cmp_mode,
  				    XEXP (op0, 0), XEXP (op0, 1));
  
!   /* (eq/ne (xor x y) x) simplifies to (eq/ne x 0).  */
    if ((code == EQ || code == NE)
        && op0code == XOR
        && rtx_equal_p (XEXP (op0, 0), op1)
!       && !side_effects_p (XEXP (op0, 1)))
!     return simplify_gen_relational (code, mode, cmp_mode, op1, const0_rtx);
!   /* Likewise (eq/ne (xor x y) y) simplifies to (eq/ne y 0).  */
    if ((code == EQ || code == NE)
        && op0code == XOR
        && rtx_equal_p (XEXP (op0, 1), op1)
!       && !side_effects_p (XEXP (op0, 0)))
!     return simplify_gen_relational (code, mode, cmp_mode, op1, const0_rtx);
  
    /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)).  */
    if ((code == EQ || code == NE)
--- 3604,3624 ----
      return simplify_gen_relational (code, mode, cmp_mode,
  				    XEXP (op0, 0), XEXP (op0, 1));
  
!   /* (eq/ne (xor x y) x) simplifies to (eq/ne y 0).  */
    if ((code == EQ || code == NE)
        && 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);
! 
!   /* 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);
  
    /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)).  */
    if ((code == EQ || code == NE)
--- /dev/null	2006-03-11 08:41:44.866675760 -0800
+++ testsuite/gcc.c-torture/execute/pr27671-1.c	2006-05-20 13:27:54.000000000 -0700
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/27671.
+   The combiner used to simplify "a ^ b == a" to "a" via
+   simplify_relational_operation_1 in simplify-rtx.c.  */
+
+extern void abort (void) __attribute__ ((noreturn));
+extern void exit (int) __attribute__ ((noreturn));
+
+static int __attribute__((noinline))
+foo (int a, int b)
+{
+  int c = a ^ b;
+  if (c == a)
+    abort ();
+}
+
+int
+main (void)
+{
+  foo (0, 1);
+  exit (0);
+}
--- /dev/null	2006-03-11 08:41:44.866675760 -0800
+++ testsuite/gcc.dg/pr27671-2.c	2006-05-20 18:10:14.000000000 -0700
@@ -0,0 +1,24 @@
+/* PR rtl-optimization/27671.
+   The combiner used to simplify "a ^ b == a" to "a" via
+   simplify_relational_operation_1 in simplify-rtx.c.  */
+/* { dg-do run } */
+/* { dg-options "-O1" } */
+/* { dg-options "-O1 -march=pentium4" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+
+extern void abort (void) __attribute__ ((noreturn));
+extern void exit (int) __attribute__ ((noreturn));
+
+static void __attribute__ ((noinline))
+bar (int k)
+{
+  int n = k % 2;
+  if (n == 0)
+    abort ();
+}
+
+int
+main (void)
+{  
+  bar (1);
+  exit (0);
+}


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