Ok, I see. This might be profitable to do that. So fold_truth_op hunk looks like this
@@ -5149,13 +5176,6 @@ fold_truthop (location_t loc, enum tree_ build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), ll_arg, rl_arg), build_int_cst (TREE_TYPE (ll_arg), 0)); - - if (LOGICAL_OP_NON_SHORT_CIRCUIT) - { - if (code != orig_code || lhs != orig_lhs || rhs != orig_rhs) - return build2_loc (loc, code, truth_type, lhs, rhs); - return NULL_TREE; - } } /* See if the comparisons can be merged. Then get all the parameters for @@ -8380,13 +8400,77 @@ fold_truth_andor (location_t loc, enum t lhs is another similar operation, try to merge its rhs with our rhs. Then try to merge our lhs and rhs. */ if (TREE_CODE (arg0) == code - && 0 != (tem = fold_truthop (loc, code, type, - TREE_OPERAND (arg0, 1), arg1))) + && 0 != (tem = fold_truth_andor_1 (loc, code, type, + TREE_OPERAND (arg0, 1), arg1))) return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem); - if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0) + if ((tem = fold_truth_andor_1 (loc, code, type, arg0, arg1)) != 0) return tem; + if ((BRANCH_COST (optimize_function_for_speed_p (cfun), + false) >= 2) + && LOGICAL_OP_NON_SHORT_CIRCUIT + && simple_operand_p_2 (arg1)) + { + enum tree_code ncode; + + if (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR) + { + ncode = (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR); + + /* Transform ((A AND-IF B) AND-IF C) into (A AND-IF (B AND C)), + or ((A OR-IF B) OR-IF C) into (A OR-IF (B OR C)) + We don't want to pack more than two leafs to a non-IF AND/OR + expression. + If tree-code of left-hand operand isn't an AND/OR-IF code and not + equal to CODE, then we don't want to add right-hand operand. + If the inner right-hand side of left-hand operand has + side-effects, or isn't simple, then we can't add to it, + as otherwise we might destroy if-sequence. */ + if (TREE_CODE (arg0) == code + /* Needed for sequence points to handle trappings, and + side-effects. */ + && simple_operand_p_2 (TREE_OPERAND (arg0, 1))) + { + tem = fold_build2_loc (loc, ncode, type, TREE_OPERAND (arg0, 1), + arg1); + return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), + tem); + } + /* Transform (A AND-IF B) into (A AND B), or (A OR-IF B) + into (A OR B). + For sequence point consistancy, we need to check for trapping, + and side-effects. */ + else if (simple_operand_p_2 (arg0)) + return fold_build2_loc (loc, ncode, type, arg0, arg1); + } + else + { + ncode = (code == TRUTH_AND_EXPR ? TRUTH_ANDIF_EXPR + : TRUTH_ORIF_EXPR); + /* Transform ((A AND-IF B) AND C) into (A AND-IF (B AND C)), + or ((A OR-IF B) OR C) into (A OR-IF (B OR C)) + We don't want to pack more than two leafs to a non-IF AND/OR + expression. + If tree-code of left-hand operand isn't an AND/OR-IF code and not + equal to NCODE, then we don't want to add right-hand operand. + If the inner right-hand side of left-hand operand has + side-effects, or isn't simple, then we can't add to it, + as otherwise we might destroy if-sequence. */ + if (TREE_CODE (arg0) == ncode + /* Needed for sequence points to handle trappings, and + side-effects. */ + && simple_operand_p_2 (TREE_OPERAND (arg0, 1))) + { + tem = fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 1), + arg1); + return fold_build2_loc (loc, ncode, type, + TREE_OPERAND (arg0, 0), tem); + } + } + + } + return NULL_TREE; } Ok, with other changes you mentioned? Regards, Kai