* [PATCH][1/2] Remove GENERIC comparison folding from fold_stmt
@ 2015-07-29 12:42 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-07-29 12:42 UTC (permalink / raw)
To: gcc-patches
This removes folding of conditions in GIMPLE_CONDs using fold_binary
from fold_stmt. All cases appearing during bootstrap and regtest on
x86_64-unknown-linux-gnu are now handled by gimple_simplify and
match.pd patterns (remember this is just two bare operand cases).
I've verified this using the 2nd patch below which passes bootstrap &
regtest.
Boostrapped and tested on x86_64-unknown-linux-gnu.
[2/2] will do the same for comparisons on the RHS of assignments
(note fold_stmt never folded the comparison embedded in RHS
[VEC_]COND_EXPRs, only forward_propagate_into_cond does right now).
Richard.
2015-07-29 Richard Biener <rguenther@suse.de>
* gimple-fold.c (fold_gimple_cond): Remove.
(fold_stmt_1): Do not call it.
Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c (revision 226340)
+++ gcc/gimple-fold.c (working copy)
@@ -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:
Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c (revision 226340)
+++ gcc/gimple-fold.c (working copy)
@@ -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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-07-29 12:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-29 12:42 [PATCH][1/2] Remove GENERIC comparison folding from fold_stmt Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).