===================================================================
@@ -529,33 +529,6 @@ fold_gimple_assign (gimple_stmt_iterator
return NULL_TREE;
}
-/* Attempt to fold a conditional statement. Return true if any changes were
- made. We only attempt to fold the condition expression, and do not perform
- any transformation that would require alteration of the cfg. It is
- assumed that the operands have been previously folded. */
-
-static bool
-fold_gimple_cond (gcond *stmt)
-{
- tree result = fold_binary_loc (gimple_location (stmt),
- gimple_cond_code (stmt),
- boolean_type_node,
- gimple_cond_lhs (stmt),
- gimple_cond_rhs (stmt));
-
- if (result)
- {
- STRIP_USELESS_TYPE_CONVERSION (result);
- if (is_gimple_condexpr (result))
- {
- gimple_cond_set_condition_from_tree (stmt, result);
- return true;
- }
- }
-
- return false;
-}
-
/* Replace a statement at *SI_P with a sequence of statements in STMTS,
adjusting the replacement stmts location and virtual operands.
@@ -3711,10 +3684,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
break;
}
- case GIMPLE_COND:
- changed |= fold_gimple_cond (as_a <gcond *> (stmt));
- break;
-
case GIMPLE_CALL:
changed |= gimple_fold_call (gsi, inplace);
break;
Testing patch:
===================================================================
@@ -548,6 +551,13 @@ fold_gimple_cond (gcond *stmt)
STRIP_USELESS_TYPE_CONVERSION (result);
if (is_gimple_condexpr (result))
{
+ /* Folding changes 1 != 0 to 1 thus avoid false changed
+ reporting if the condition didn't really change. */
+ if (is_gimple_val (result)
+ && gimple_cond_code (stmt) == NE_EXPR
+ && integer_zerop (gimple_cond_rhs (stmt))
+ && operand_equal_p (gimple_cond_lhs (stmt), result, 0))
+ return false;
gimple_cond_set_condition_from_tree (stmt, result);
return true;
}
@@ -3712,8 +3708,11 @@ fold_stmt_1 (gimple_stmt_iterator *gsi,
}
case GIMPLE_COND:
- changed |= fold_gimple_cond (as_a <gcond *> (stmt));
- break;
+ {
+ bool cg = fold_gimple_cond (as_a <gcond *> (stmt));
+ gcc_assert (!cg);
+ break;
+ }
case GIMPLE_CALL:
changed |= gimple_fold_call (gsi, inplace);