Index: fold-const.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v retrieving revision 1.498 diff -u -d -b -w -p -c -3 -p -r1.498 fold-const.c cvs diff: conflicting specifications of output style *** fold-const.c 28 Jan 2005 16:35:46 -0000 1.498 --- fold-const.c 31 Jan 2005 01:59:30 -0000 *************** static tree optimize_minmax_comparison ( *** 121,128 **** static tree extract_muldiv (tree, tree, enum tree_code, tree); static tree extract_muldiv_1 (tree, tree, enum tree_code, tree); static int multiple_of_p (tree, tree, tree); ! static tree fold_binary_op_with_conditional_arg (enum tree_code, tree, tree, ! tree, int); static bool fold_real_zero_addition_p (tree, tree, int); static tree fold_mathfn_compare (enum built_in_function, enum tree_code, tree, tree, tree); --- 121,127 ---- static tree extract_muldiv (tree, tree, enum tree_code, tree); static tree extract_muldiv_1 (tree, tree, enum tree_code, tree); static int multiple_of_p (tree, tree, tree); ! static tree fold_binary_op_with_conditional_arg (tree, enum tree_code, tree, tree, int); static bool fold_real_zero_addition_p (tree, tree, int); static tree fold_mathfn_compare (enum built_in_function, enum tree_code, tree, tree, tree); *************** constant_boolean_node (int value, tree t *** 5384,5392 **** possible. */ static tree ! fold_binary_op_with_conditional_arg (enum tree_code code, tree type, ! tree cond, tree arg, int cond_first_p) { tree test, true_value, false_value; tree lhs = NULL_TREE; tree rhs = NULL_TREE; --- 5383,5393 ---- possible. */ static tree ! fold_binary_op_with_conditional_arg (tree t, enum tree_code code, tree cond, tree arg, int cond_first_p) { + const tree type = TREE_TYPE (t); + tree cond_type = cond_first_p ? TREE_TYPE (TREE_OPERAND (t, 0)) : TREE_TYPE (TREE_OPERAND (t, 1)); + tree arg_type = cond_first_p ? TREE_TYPE (TREE_OPERAND (t, 1)) : TREE_TYPE (TREE_OPERAND (t, 0)); tree test, true_value, false_value; tree lhs = NULL_TREE; tree rhs = NULL_TREE; *************** fold_binary_op_with_conditional_arg (enu *** 5418,5429 **** --- 5419,5437 ---- false_value = constant_boolean_node (false, testtype); } + arg = fold_convert (arg_type, arg); if (lhs == 0) + { + true_value = fold_convert (cond_type, true_value); lhs = fold (cond_first_p ? build2 (code, type, true_value, arg) : build2 (code, type, arg, true_value)); + } if (rhs == 0) + { + false_value = fold_convert (cond_type, false_value); rhs = fold (cond_first_p ? build2 (code, type, false_value, arg) : build2 (code, type, arg, false_value)); + } test = fold (build3 (COND_EXPR, type, test, lhs, rhs)); return fold_convert (type, test); *************** fold (tree expr) *** 6465,6480 **** if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) { ! tem = fold_binary_op_with_conditional_arg (code, type, arg0, arg1, ! /*cond_first_p=*/1); if (tem != NULL_TREE) return tem; } if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) { ! tem = fold_binary_op_with_conditional_arg (code, type, arg1, arg0, ! /*cond_first_p=*/0); if (tem != NULL_TREE) return tem; } --- 6473,6486 ---- if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) { ! tem = fold_binary_op_with_conditional_arg (t, code, arg0, arg1, /*cond_first_p=*/1); if (tem != NULL_TREE) return tem; } if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) { ! tem = fold_binary_op_with_conditional_arg (t, code, arg1, arg0, /*cond_first_p=*/0); if (tem != NULL_TREE) return tem; }