Skip to content

Commit

Permalink
Inline comparisons with literal lists of length one
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Nov 26, 2023
1 parent e983309 commit 25d1268
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions erts/emulator/beam/jit/arm/instr_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,30 @@ void BeamModuleAssembler::emit_is_eq_exact(const ArgLabel &Fail,
return;
}

/* Inline the comparison if the RHS argument is a list of one
* immediate value such as `[42]` or `[a]`. */
if (Y.isLiteral()) {
Eterm literal = beamfile_get_literal(beam, Y.as<ArgLiteral>().get());
if (is_list(literal) && is_immed(CAR(list_val(literal))) &&
is_nil(CDR(list_val(literal)))) {
arm::Gp cons_ptr;

comment("inlined exact comparison with %T", literal);
if (!exact_type<BeamTypeId::Cons>(X)) {
emit_is_cons(resolve_beam_label(Fail, dispUnknown), x.reg);
}
cons_ptr = emit_ptr_val(TMP1, x.reg);
a.sub(TMP1, cons_ptr, imm(TAG_PRIMARY_LIST));
a.ldp(TMP2, TMP3, arm::Mem(TMP1));
cmp(TMP2, CAR(list_val(literal)));
mov_imm(TMP4, NIL);
a.ccmp(TMP3, TMP4, imm(NZCV::kNone), imm(arm::CondCode::kEQ));
a.b_ne(resolve_beam_label(Fail, disp1MB));

return;
}
}

/* Both operands are registers or literals. */
Label next = a.newLabel();
auto y = load_source(Y, ARG2);
Expand Down

0 comments on commit 25d1268

Please sign in to comment.