re PR middle-end/27302 (Fold does not fold (i < j) == (j > i) to 1)
authorRichard Guenther <rguenther@suse.de>
Wed, 10 May 2006 10:22:39 +0000 (10:22 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 May 2006 10:22:39 +0000 (10:22 +0000)
2006-05-10  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/27302
* fold-const.c (operand_equal_p): For two comparisons,
try comparison of one comparison code swapped if that yields
the same code.

* gcc.dg/torture/pr27302.c: New testcase.

From-SVN: r113670

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr27302.c [new file with mode: 0644]

index 6cd1fcc76f37a20eb0bb620f1f272a529ba10e9d..c52d9dd0db02617c356ac772e0ffb2fcde6f53a5 100644 (file)
@@ -1,3 +1,10 @@
+2006-05-10  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/27302
+       * fold-const.c (operand_equal_p): For two comparisons,
+       try comparison of one comparison code swapped if that yields
+       the same code.
+
 2006-05-10  Ben Elliston  <bje@au.ibm.com>
 
        * tree-pretty-print.c (pretty_print_string): No need to handle
index 26e53c0c32ccf940636e233a5cfdd071ab353813..030bcb1c951306469072fa1d220dab43465decd1 100644 (file)
@@ -2489,6 +2489,22 @@ operand_equal_p (tree arg0, tree arg1, unsigned int flags)
   STRIP_NOPS (arg0);
   STRIP_NOPS (arg1);
 
+  /* In case both args are comparisons but with different comparison
+     code, try to swap the comparison operands of one arg to produce
+     a match and compare that variant.  */
+  if (TREE_CODE (arg0) != TREE_CODE (arg1)
+      && COMPARISON_CLASS_P (arg0)
+      && COMPARISON_CLASS_P (arg1))
+    {
+      enum tree_code swap_code = swap_tree_comparison (TREE_CODE (arg1));
+
+      if (TREE_CODE (arg0) == swap_code)
+       return operand_equal_p (TREE_OPERAND (arg0, 0),
+                               TREE_OPERAND (arg1, 1), flags)
+              && operand_equal_p (TREE_OPERAND (arg0, 1),
+                                  TREE_OPERAND (arg1, 0), flags);
+    }
+
   if (TREE_CODE (arg0) != TREE_CODE (arg1)
       /* This is needed for conversions and for COMPONENT_REF.
         Might as well play it safe and always test this.  */
index 9eff9f48d4060c493ee36c6b2b62a7aae37dc236..7e7c9982e7598a6848b25f5759a60de3298533f6 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-10  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/27302
+       * gcc.dg/torture/pr27302.c: New testcase.
+
 2006-05-09  Dirk Mueller  <dmueller@suse.de>
        Richard Guenther  <rguenther@suse.de>
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr27302.c b/gcc/testsuite/gcc.dg/torture/pr27302.c
new file mode 100644 (file)
index 0000000..0e41fc3
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+
+extern void link_error (void);
+
+void test0 (int a, int b)
+{
+  if ((a < b) != (b > a))
+    link_error ();
+}
+
+int main()
+{
+  test0 (1, 2);
+  return 0;
+}