Skip to content

Commit

Permalink
Merge branch 'more-op-opts'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 25, 2018
2 parents b6030ce + e569015 commit 6f40cbd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/spesh/optimize.c
Expand Up @@ -80,6 +80,24 @@ MVMint16 MVM_spesh_add_spesh_slot(MVMThreadContext *tc, MVMSpeshGraph *g, MVMCol
return g->num_spesh_slots++;
}

/* If an `isnull` is on something we know the type of or value of, then we
* can quickly verify the type is not based on the null REPR and turn it
* into a constant. */
static void optimize_isnull(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
MVMSpeshIns *ins) {
MVMSpeshFacts *obj_facts = MVM_spesh_get_facts(tc, g, ins->operands[1]);
if (obj_facts->flags & MVM_SPESH_FACT_KNOWN_TYPE) {
MVMint32 is_null = REPR(obj_facts->type)->ID == MVM_REPR_ID_MVMNull;
MVMSpeshFacts *result_facts = MVM_spesh_get_facts(tc, g, ins->operands[0]);
MVM_spesh_use_facts(tc, g, obj_facts);
ins->info = MVM_op_get_op(MVM_OP_const_i64_16);
ins->operands[1].lit_i16 = is_null;
result_facts->flags |= MVM_SPESH_FACT_KNOWN_VALUE;
result_facts->value.i = is_null;
MVM_spesh_facts_depend(tc, g, result_facts, obj_facts);
}
}

static void optimize_repr_op(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
MVMSpeshIns *ins, MVMint32 type_operand);

Expand Down Expand Up @@ -115,6 +133,8 @@ static void optimize_method_lookup(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSp

/* Tweak facts for the target, given we know the method. */
MVMSpeshFacts *meth_facts = MVM_spesh_get_and_use_facts(tc, g, ins->operands[0]);
meth_facts->flags |= MVM_SPESH_FACT_KNOWN_TYPE;
meth_facts->type = meth->st->WHAT;
meth_facts->flags |= MVM_SPESH_FACT_KNOWN_VALUE;
meth_facts->value.o = meth;

Expand Down Expand Up @@ -2066,6 +2086,9 @@ static void optimize_bb_switch(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshB
case MVM_OP_set:
copy_facts(tc, g, ins->operands[0], ins->operands[1]);
break;
case MVM_OP_isnull:
optimize_isnull(tc, g, bb, ins);
break;
case MVM_OP_istrue:
case MVM_OP_isfalse:
optimize_istrue_isfalse(tc, g, bb, ins);
Expand Down

0 comments on commit 6f40cbd

Please sign in to comment.