aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2006-05-10 10:22:39 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2006-05-10 10:22:39 +0000
commita04d8591f266f810cf4681930772982444227b83 (patch)
tree2e26bba9ef58b3eadcdafeb6f4d3d820b548704f /gcc/fold-const.c
parent4db60bd06f820684418d7bb179d6edee80cddb08 (diff)
downloadgcc-a04d8591f266f810cf4681930772982444227b83.zip
gcc-a04d8591f266f810cf4681930772982444227b83.tar.gz
gcc-a04d8591f266f810cf4681930772982444227b83.tar.bz2
re PR middle-end/27302 (Fold does not fold (i < j) == (j > i) to 1)
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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 26e53c0..030bcb1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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. */