Hi, The uses of the whole expression in the current fold_ARITY are blocking transition to fold_ARITY (code, type, op0[, op1[, op2]]).
Below I am showing places where we need to make changes in the form of a patch. Wherever 't' is used, we need to make changes. The first hunk comes from fold_unary, and the last one comes from the fold_ternary. The rest comes from fold_binary. I've already got suggestions from Zack and Roger for fold_ternary. I think I'll replace a call to fold_builtin with fold_builtin_1 and change fold_builtin_1 to take fn, arglist, and possibly static chain if needed (as suggested by Roger on IRC). COMPARISON_CLASS_P (t) is easy because it's equivalent to TREE_CODE_CLASS (code) == tcc_comparison. I might need help on others. I'll try to go through these "KAZU" one by one, but if you could volunteer to fix one, you are more than welcome. Suggestions like "Here is what I would do" would be fine, too. Kazu Hirata diff -u fold-const.c fold-const.c --- fold-const.c 6 Mar 2005 00:44:01 -0000 +++ fold-const.c 6 Mar 2005 00:45:38 -0000 @@ -6802,6 +6802,7 @@ { /* Don't leave an assignment inside a conversion unless assigning a bitfield. */ + /* KAZU. */ tem = copy_node (t); TREE_OPERAND (tem, 0) = TREE_OPERAND (op0, 1); /* First do the assignment, then return converted constant. */ @@ -7152,6 +7153,7 @@ if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) { + /* KAZU. */ tem = fold_binary_op_with_conditional_arg (t, code, arg0, arg1, /*cond_first_p=*/1); if (tem != NULL_TREE) @@ -7160,6 +7162,7 @@ if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) { + /* KAZU. */ tem = fold_binary_op_with_conditional_arg (t, code, arg1, arg0, /*cond_first_p=*/0); if (tem != NULL_TREE) @@ -7170,6 +7173,7 @@ switch (code) { case RANGE_EXPR: + /* KAZU. */ if (TREE_CONSTANT (t) != wins) { tem = copy_node (t); @@ -8611,6 +8615,7 @@ } /* See if we can build a range comparison. */ + /* KAZU. */ if (0 != (tem = fold_range_test (t))) return tem; @@ -8727,6 +8732,7 @@ /* If this is a comparison of two exprs that look like an ARRAY_REF of the same object, then we can fold this to a comparison of the two offsets. */ + /* KAZU. */ if (COMPARISON_CLASS_P (t)) { tree base0, offset0, base1, offset1; @@ -9142,6 +9148,7 @@ && (TREE_CODE (arg0) == MIN_EXPR || TREE_CODE (arg0) == MAX_EXPR) && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) + /* KAZU. */ return optimize_minmax_comparison (t); /* If we are comparing an ABS_EXPR with a constant, we can @@ -9845,6 +9852,7 @@ && TREE_CODE (TREE_OPERAND (op0, 0)) == FUNCTION_DECL && DECL_BUILT_IN (TREE_OPERAND (op0, 0))) { + /* KAZU. */ tree tmp = fold_builtin (t, false); if (tmp) return tmp;