Commit 3a96b5eb by Richard Kenner

(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
parent 4013a709
...@@ -4730,9 +4730,10 @@ fold (expr) ...@@ -4730,9 +4730,10 @@ fold (expr)
if (TREE_CODE (tem) != TRUTH_NOT_EXPR) if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{ {
arg0 = TREE_OPERAND (t, 0) = tem; arg0 = TREE_OPERAND (t, 0) = tem;
TREE_OPERAND (t, 1) = TREE_OPERAND (t, 2); arg1 = TREE_OPERAND (t, 2);
TREE_OPERAND (t, 2) = arg1; TREE_OPERAND (t, 2) = TREE_OPERAND (t, 1);
arg1 = TREE_OPERAND (t, 1); TREE_OPERAND (t, 1) = arg1;
STRIP_NOPS (arg1);
} }
} }
...@@ -4751,6 +4752,8 @@ fold (expr) ...@@ -4751,6 +4752,8 @@ fold (expr)
tree arg2 = TREE_OPERAND (t, 2); tree arg2 = TREE_OPERAND (t, 2);
enum tree_code comp_code = TREE_CODE (arg0); 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), /* If we have A op 0 ? A : -A, this is A, -A, abs (A), or abs (-A),
depending on the comparison operation. */ depending on the comparison operation. */
if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1))) if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1)))
...@@ -4792,6 +4795,11 @@ fold (expr) ...@@ -4792,6 +4795,11 @@ fold (expr)
if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1), if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1),
arg2, TREE_OPERAND (arg0, 0))) arg2, TREE_OPERAND (arg0, 0)))
{
tree comp_op0 = TREE_OPERAND (arg0, 0);
tree comp_op1 = TREE_OPERAND (arg0, 1);
tree comp_type = TREE_TYPE (comp_op0);
switch (comp_code) switch (comp_code)
{ {
case EQ_EXPR: case EQ_EXPR:
...@@ -4801,11 +4809,14 @@ fold (expr) ...@@ -4801,11 +4809,14 @@ fold (expr)
case LE_EXPR: case LE_EXPR:
case LT_EXPR: case LT_EXPR:
return pedantic_non_lvalue return pedantic_non_lvalue
(fold (build (MIN_EXPR, type, arg1, arg2))); (convert (type, (fold (build (MIN_EXPR, comp_type,
comp_op0, comp_op1)))));
case GE_EXPR: case GE_EXPR:
case GT_EXPR: case GT_EXPR:
return pedantic_non_lvalue return pedantic_non_lvalue
(fold (build (MAX_EXPR, type, arg1, arg2))); (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, /* If this is A op C1 ? A : C2 with C1 and C2 constant integers,
...@@ -4883,9 +4894,10 @@ fold (expr) ...@@ -4883,9 +4894,10 @@ fold (expr)
if (TREE_CODE (tem) != TRUTH_NOT_EXPR) if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{ {
arg0 = TREE_OPERAND (t, 0) = tem; arg0 = TREE_OPERAND (t, 0) = tem;
TREE_OPERAND (t, 1) = TREE_OPERAND (t, 2); arg1 = TREE_OPERAND (t, 2);
TREE_OPERAND (t, 2) = arg1; TREE_OPERAND (t, 2) = TREE_OPERAND (t, 1);
arg1 = TREE_OPERAND (t, 1); TREE_OPERAND (t, 1) = arg1;
STRIP_NOPS (arg1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment