cse.c | 7 -------
linearize.c | 23 ++++++++++++-----------
2 files changed, 12 insertions(+), 18 deletions(-)
@@ -317,13 +317,6 @@ static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction
b2 = i2->bb;
/*
- * PHI-nodes do not care where they are - the only thing that matters
- * are the PHI _sources_.
- */
- if (i1->opcode == OP_PHI)
- return cse_one_instruction(i1, i2);
-
- /*
* Currently we only handle the uninteresting degenerate case where
* the CSE is inside one basic-block.
*/
@@ -1419,9 +1419,14 @@ pseudo_t linearize_cond_branch(struct entrypoint *ep, struct expression *expr, s
{
pseudo_t cond;
- if (!expr || !bb_reachable(ep->active))
+ if (!bb_reachable(ep->active))
return VOID;
+ if (!expr) {
+ add_goto(ep, bb_true);
+ return VOID;
+ }
+
switch (expr->type) {
case EXPR_STRING:
@@ -2055,21 +2060,15 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
struct statement *statement = stmt->iterator_statement;
struct statement *post_statement = stmt->iterator_post_statement;
struct expression *post_condition = stmt->iterator_post_condition;
- struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end;
+ struct basic_block *loop_body, *loop_continue, *loop_end;
concat_symbol_list(stmt->iterator_syms, &ep->syms);
linearize_statement(ep, pre_statement);
- loop_body = loop_top = alloc_basic_block(ep, stmt->pos);
+ loop_body = alloc_basic_block(ep, stmt->pos);
loop_continue = alloc_basic_block(ep, stmt->pos);
loop_end = alloc_basic_block(ep, stmt->pos);
- /* An empty post-condition means that it's the same as the pre-condition */
- if (!post_condition) {
- loop_top = alloc_basic_block(ep, stmt->pos);
- set_activeblock(ep, loop_top);
- }
-
if (pre_condition)
linearize_cond_branch(ep, pre_condition, loop_body, loop_end);
@@ -2082,10 +2081,12 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
set_activeblock(ep, loop_continue);
linearize_statement(ep, post_statement);
+
+ /* No post-condition means that it's the same as the pre-condition */
if (!post_condition)
- add_goto(ep, loop_top);
+ linearize_cond_branch(ep, pre_condition, loop_body, loop_end);
else
- linearize_cond_branch(ep, post_condition, loop_top, loop_end);
+ linearize_cond_branch(ep, post_condition, loop_body, loop_end);
set_activeblock(ep, loop_end);
break;
}