aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1995-01-13 19:16:09 -0500
committerRichard Kenner <kenner@gcc.gnu.org>1995-01-13 19:16:09 -0500
commit3a96b5ebb4116414c32f5b79dc9964a3c842a0c7 (patch)
treed7f660b2ca608366bad4b5712c535050b1965e79
parent4013a709018d4579b052a7a19322b2e969aa96a9 (diff)
downloadgcc-3a96b5ebb4116414c32f5b79dc9964a3c842a0c7.zip
gcc-3a96b5ebb4116414c32f5b79dc9964a3c842a0c7.tar.gz
gcc-3a96b5ebb4116414c32f5b79dc9964a3c842a0c7.tar.bz2
(fold, case COND_EXPR): Properly swap args 1 and 2.
Strip nops from ARG2, just like ARG1. Make {MIN,MAX}_EXPR properly when type of result different than args. From-SVN: r8745
-rw-r--r--gcc/fold-const.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4272336..9d40401 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4730,9 +4730,10 @@ fold (expr)
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{
arg0 = TREE_OPERAND (t, 0) = tem;
- TREE_OPERAND (t, 1) = TREE_OPERAND (t, 2);
- TREE_OPERAND (t, 2) = arg1;
- arg1 = TREE_OPERAND (t, 1);
+ arg1 = TREE_OPERAND (t, 2);
+ TREE_OPERAND (t, 2) = TREE_OPERAND (t, 1);
+ TREE_OPERAND (t, 1) = arg1;
+ STRIP_NOPS (arg1);
}
}
@@ -4751,6 +4752,8 @@ fold (expr)
tree arg2 = TREE_OPERAND (t, 2);
enum tree_code comp_code = TREE_CODE (arg0);
+ STRIP_NOPS (arg2);
+
/* If we have A op 0 ? A : -A, this is A, -A, abs (A), or abs (-A),
depending on the comparison operation. */
if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1)))
@@ -4792,21 +4795,29 @@ fold (expr)
if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1),
arg2, TREE_OPERAND (arg0, 0)))
- switch (comp_code)
- {
- case EQ_EXPR:
- return pedantic_non_lvalue (convert (type, arg2));
- case NE_EXPR:
- return pedantic_non_lvalue (convert (type, arg1));
- case LE_EXPR:
- case LT_EXPR:
- return pedantic_non_lvalue
- (fold (build (MIN_EXPR, type, arg1, arg2)));
- case GE_EXPR:
- case GT_EXPR:
- return pedantic_non_lvalue
- (fold (build (MAX_EXPR, type, arg1, arg2)));
- }
+ {
+ tree comp_op0 = TREE_OPERAND (arg0, 0);
+ tree comp_op1 = TREE_OPERAND (arg0, 1);
+ tree comp_type = TREE_TYPE (comp_op0);
+
+ switch (comp_code)
+ {
+ case EQ_EXPR:
+ return pedantic_non_lvalue (convert (type, arg2));
+ case NE_EXPR:
+ return pedantic_non_lvalue (convert (type, arg1));
+ case LE_EXPR:
+ case LT_EXPR:
+ return pedantic_non_lvalue
+ (convert (type, (fold (build (MIN_EXPR, comp_type,
+ comp_op0, comp_op1)))));
+ case GE_EXPR:
+ case GT_EXPR:
+ return pedantic_non_lvalue
+ (convert (type, fold (build (MAX_EXPR, comp_type,
+ comp_op0, comp_op1))));
+ }
+ }
/* If this is A op C1 ? A : C2 with C1 and C2 constant integers,
we might still be able to simplify this. For example,
@@ -4883,9 +4894,10 @@ fold (expr)
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{
arg0 = TREE_OPERAND (t, 0) = tem;
- TREE_OPERAND (t, 1) = TREE_OPERAND (t, 2);
- TREE_OPERAND (t, 2) = arg1;
- arg1 = TREE_OPERAND (t, 1);
+ arg1 = TREE_OPERAND (t, 2);
+ TREE_OPERAND (t, 2) = TREE_OPERAND (t, 1);
+ TREE_OPERAND (t, 1) = arg1;
+ STRIP_NOPS (arg1);
}
}