[wasm][liftoff] Use the comparison lookahead also for kExprIf

There was already a lookahead implementation in Liftoff for the case
where a comparison was followed by kExprBrIf. This CL extends this
lookahead implementation to kExprIf as well. This extension reduces the
size of the code generated by Liftoff in the Epic benchmark by 1.5%.

R=clemensb@chromium.org

Bug: v8:11873, v8:11862
Change-Id: If4428bdd64eedcdd6dc543efc3b9945cbd8be3cc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2953322
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75088}
This commit is contained in:
Andreas Haas 2021-06-10 17:59:45 +02:00 committed by V8 LUCI CQ
parent 67f489a29a
commit 57658dd9d6

View File

@ -1255,7 +1255,23 @@ class LiftoffCompiler {
// Test the condition, jump to else if zero.
Register value = __ PopToRegister().gp();
__ emit_cond_jump(kEqual, if_block->else_state->label.get(), kI32, value);
if (!has_outstanding_op()) {
// Unary "equal" means "equals zero".
__ emit_cond_jump(kEqual, if_block->else_state->label.get(), kI32, value);
} else if (outstanding_op_ == kExprI32Eqz) {
// Unary "unequal" means "not equals zero".
__ emit_cond_jump(kUnequal, if_block->else_state->label.get(), kI32,
value);
outstanding_op_ = kNoOutstandingOp;
} else {
// Otherwise, it's an i32 compare opcode.
LiftoffCondition cond = Negate(GetCompareCondition(outstanding_op_));
Register rhs = value;
Register lhs = __ PopToRegister(LiftoffRegList::ForRegs(rhs)).gp();
__ emit_cond_jump(cond, if_block->else_state->label.get(), kI32, lhs,
rhs);
outstanding_op_ = kNoOutstandingOp;
}
// Store the state (after popping the value) for executing the else branch.
if_block->else_state->state.Split(*__ cache_state());
@ -1702,7 +1718,8 @@ class LiftoffCompiler {
template <WasmOpcode opcode>
void EmitI32CmpOp(FullDecoder* decoder) {
DCHECK(decoder->lookahead(0, opcode));
if (decoder->lookahead(1, kExprBrIf) && !for_debugging_) {
if ((decoder->lookahead(1, kExprBrIf) || decoder->lookahead(1, kExprIf)) &&
!for_debugging_) {
DCHECK(!has_outstanding_op());
outstanding_op_ = opcode;
return;