Permalink
Browse files

Clean up dead variables in PHI nodes.

Since those paths will never be taken, their facts are not relevant.
This means the merged facts can be more accurate. This allows for far
better handling of the case where an optional parameter was passed;
we only care about the facts on the variable, not those on the (dead)
default value.
  • Loading branch information...
jnthn committed Jun 14, 2017
1 parent bca35a4 commit c0fcf1d7d83cf15cc1ce471eb6994fb8fbf1d5fe
Showing with 19 additions and 0 deletions.
  1. +19 −0 src/spesh/optimize.c
View
@@ -1375,6 +1375,23 @@ static void optimize_throwcat(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB
MVM_free(handlers_found);
}
static void eliminate_phi_dead_reads(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
MVMuint32 operand = 1;
MVMuint32 insert_pos = 1;
MVMuint32 num_operands = ins->info->num_operands;
while (operand < num_operands) {
if (get_facts_direct(tc, g, ins->operands[operand])->flags & MVM_SPESH_FACT_DEAD_WRITER) {
num_operands--;
}
else {
ins->operands[insert_pos] = ins->operands[operand];
insert_pos++;
}
operand++;
}
if (num_operands != ins->info->num_operands)
ins->info = get_phi(tc, g, num_operands);
}
static void analyze_phi(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
MVMuint32 operand;
MVMint32 common_flags;
@@ -1383,6 +1400,8 @@ static void analyze_phi(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins
MVMuint32 needs_merged_with_log_guard = 0;
MVMSpeshFacts *target_facts = get_facts_direct(tc, g, ins->operands[0]);
eliminate_phi_dead_reads(tc, g, ins);
common_flags = get_facts_direct(tc, g, ins->operands[1])->flags;
common_type = get_facts_direct(tc, g, ins->operands[1])->type;
common_decont_type = get_facts_direct(tc, g, ins->operands[1])->decont_type;

0 comments on commit c0fcf1d

Please sign in to comment.