aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPat Haugen <pthaugen@us.ibm.com>2005-03-25 20:08:30 +0000
committerDavid Edelsohn <dje@gcc.gnu.org>2005-03-25 15:08:30 -0500
commita10d70babdbb3018f3ad9824b2158779844a7999 (patch)
tree8bfacbc21662a474c461c0e46f944418c5db96b7
parentd5bdce497f4c22d109e3f5f213c575d2c6001785 (diff)
downloadgcc-a10d70babdbb3018f3ad9824b2158779844a7999.zip
gcc-a10d70babdbb3018f3ad9824b2158779844a7999.tar.gz
gcc-a10d70babdbb3018f3ad9824b2158779844a7999.tar.bz2
re PR tree-optimization/20470 (Branching sequence generated for ABS(x-y))
2005-03-25 Pat Haugen <pthaugen@us.ibm.com> PR tree-optimization/20470 * fold-const.c (fold_cond_expr_with_comparison): Recognize/fold ABS(x-y). From-SVN: r97062
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c12
2 files changed, 16 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4a096a0..71e4822 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-03-25 Pat Haugen <pthaugen@us.ibm.com>
+
+ PR tree-optimization/20470
+ * fold-const.c (fold_cond_expr_with_comparison): Recognize/fold
+ ABS(x-y).
+
2005-03-25 Mike Stump <mrs@apple.com>
* config/darwin.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Don't allow 0
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index d32172f..4ac921b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4187,8 +4187,16 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
if ((FLOAT_TYPE_P (TREE_TYPE (arg01))
? real_zerop (arg01)
: integer_zerop (arg01))
- && TREE_CODE (arg2) == NEGATE_EXPR
- && operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
+ && ((TREE_CODE (arg2) == NEGATE_EXPR
+ && operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
+ /* In the case that A is of the form X-Y, '-A' (arg2) may
+ have already been folded to Y-X, check for that. */
+ || (TREE_CODE (arg1) == MINUS_EXPR
+ && TREE_CODE (arg2) == MINUS_EXPR
+ && operand_equal_p (TREE_OPERAND (arg1, 0),
+ TREE_OPERAND (arg2, 1), 0)
+ && operand_equal_p (TREE_OPERAND (arg1, 1),
+ TREE_OPERAND (arg2, 0), 0))))
switch (comp_code)
{
case EQ_EXPR: