===================================================================
@@ -8386,6 +8390,33 @@ fold_truth_andor (location_t loc, enum t
if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
return tem;
+ if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
+ && !TREE_SIDE_EFFECTS (arg1)
+ && simple_operand_p (arg1)
+ && LOGICAL_OP_NON_SHORT_CIRCUIT
+ && !FLOAT_TYPE_P (TREE_TYPE (arg1))
+ && ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
+ && TREE_CODE (TREE_CODE (arg1)) != TRUTH_NOT_EXPR)
+ || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)))))
+ {
+ if (TREE_CODE (arg0) == code
+ && !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
+ && simple_operand_p (TREE_OPERAND (arg0, 1)))
+ {
+ tem = build2_loc (loc,
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+ type, TREE_OPERAND (arg0, 1), arg1);
+ return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
+ }
+ if (!TREE_SIDE_EFFECTS (arg0)
+ && simple_operand_p (arg0))
+ return build2_loc (loc,
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+ type, arg0, arg1);
+ }
+
return NULL_TREE;
}