Skip to content

Commit 89ca48c

Browse files
backesCommit Bot
authored andcommitted
[wasm][liftoff] Fix register usage for i64_addi
The arm implementation made the assumption that the {lhs} and {dst} registers are either the same, or there is no overlap. This assumption does not hold. ia32 on the other hand has a lot of complicated logic (and unnecessary code generation) for different cases of overlap. This CL fixes the arm issue *and* simplifies the ia32 logic by making the arm assumption hold, and using it to eliminate special handling on ia32. [email protected] Bug: chromium:1146861 Change-Id: I8753c2ed70349e735c03293130c899c0c8a3a671 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2526388 Reviewed-by: Thibaud Michaud <[email protected]> Commit-Queue: Clemens Backes <[email protected]> Cr-Commit-Position: refs/heads/master@{#71060}
1 parent 4cf5d20 commit 89ca48c

4 files changed

Lines changed: 72 additions & 23 deletions

File tree

src/wasm/baseline/arm/liftoff-assembler-arm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ template <void (Assembler::*op)(Register, Register, const Operand&, SBit,
139139
SBit, Condition)>
140140
inline void I64BinopI(LiftoffAssembler* assm, LiftoffRegister dst,
141141
LiftoffRegister lhs, int32_t imm) {
142+
// The compiler allocated registers such that either {dst == lhs} or there is
143+
// no overlap between the two.
142144
DCHECK_NE(dst.low_gp(), lhs.high_gp());
143145
(assm->*op)(dst.low_gp(), lhs.low_gp(), Operand(imm), SetCC, al);
144146
// Top half of the immediate sign extended, either 0 or -1.

src/wasm/baseline/ia32/liftoff-assembler-ia32.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,31 +1454,19 @@ template <void (Assembler::*op)(Register, const Immediate&),
14541454
void (Assembler::*op_with_carry)(Register, int32_t)>
14551455
inline void OpWithCarryI(LiftoffAssembler* assm, LiftoffRegister dst,
14561456
LiftoffRegister lhs, int32_t imm) {
1457-
// First, compute the low half of the result, potentially into a temporary dst
1458-
// register if {dst.low_gp()} equals any register we need to
1459-
// keep alive for computing the upper half.
1460-
LiftoffRegList keep_alive = LiftoffRegList::ForRegs(lhs.high_gp());
1461-
Register dst_low = keep_alive.has(dst.low_gp())
1462-
? assm->GetUnusedRegister(kGpReg, keep_alive).gp()
1463-
: dst.low_gp();
1464-
1465-
if (dst_low != lhs.low_gp()) assm->mov(dst_low, lhs.low_gp());
1466-
(assm->*op)(dst_low, Immediate(imm));
1457+
// The compiler allocated registers such that either {dst == lhs} or there is
1458+
// no overlap between the two.
1459+
DCHECK_NE(dst.low_gp(), lhs.high_gp());
14671460

1468-
// Now compute the upper half, while keeping alive the previous result.
1469-
keep_alive = LiftoffRegList::ForRegs(dst_low);
1470-
Register dst_high = keep_alive.has(dst.high_gp())
1471-
? assm->GetUnusedRegister(kGpReg, keep_alive).gp()
1472-
: dst.high_gp();
1461+
// First, compute the low half of the result.
1462+
if (dst.low_gp() != lhs.low_gp()) assm->mov(dst.low_gp(), lhs.low_gp());
1463+
(assm->*op)(dst.low_gp(), Immediate(imm));
14731464

1474-
if (dst_high != lhs.high_gp()) assm->mov(dst_high, lhs.high_gp());
1465+
// Now compute the upper half.
1466+
if (dst.high_gp() != lhs.high_gp()) assm->mov(dst.high_gp(), lhs.high_gp());
14751467
// Top half of the immediate sign extended, either 0 or -1.
14761468
int32_t sign_extend = imm < 0 ? -1 : 0;
1477-
(assm->*op_with_carry)(dst_high, sign_extend);
1478-
1479-
// If necessary, move result into the right registers.
1480-
LiftoffRegister tmp_result = LiftoffRegister::ForPair(dst_low, dst_high);
1481-
if (tmp_result != dst) assm->Move(dst, tmp_result, kWasmI64);
1469+
(assm->*op_with_carry)(dst.high_gp(), sign_extend);
14821470
}
14831471
} // namespace liftoff
14841472

src/wasm/baseline/liftoff-compiler.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,9 +1244,12 @@ class LiftoffCompiler {
12441244
int32_t imm = rhs_slot.i32_const();
12451245

12461246
LiftoffRegister lhs = __ PopToRegister();
1247+
// Either reuse {lhs} for {dst}, or choose a register (pair) which does
1248+
// not overlap, for easier code generation.
1249+
LiftoffRegList pinned = LiftoffRegList::ForRegs(lhs);
12471250
LiftoffRegister dst = src_rc == result_rc
1248-
? __ GetUnusedRegister(result_rc, {lhs}, {})
1249-
: __ GetUnusedRegister(result_rc, {});
1251+
? __ GetUnusedRegister(result_rc, {lhs}, pinned)
1252+
: __ GetUnusedRegister(result_rc, pinned);
12501253

12511254
CallEmitFn(fnImm, dst, lhs, imm);
12521255
__ PushRegister(ValueType::Primitive(result_type), dst);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
load('test/mjsunit/wasm/wasm-module-builder.js');
6+
7+
const builder = new WasmModuleBuilder();
8+
builder.addGlobal(kWasmI32, 1);
9+
builder.addType(makeSig([], [kWasmF64]));
10+
// Generate function 1 (out of 1).
11+
builder.addFunction(undefined, 0 /* sig */)
12+
.addLocals(kWasmI32, 8).addLocals(kWasmI64, 3)
13+
.addBodyWithEnd([
14+
// signature: d_v
15+
// body:
16+
kExprGlobalGet, 0x00, // global.get
17+
kExprLocalSet, 0x00, // local.set
18+
kExprI32Const, 0x00, // i32.const
19+
kExprI32Eqz, // i32.eqz
20+
kExprLocalSet, 0x01, // local.set
21+
kExprGlobalGet, 0x00, // global.get
22+
kExprLocalSet, 0x02, // local.set
23+
kExprI32Const, 0x01, // i32.const
24+
kExprI32Const, 0x01, // i32.const
25+
kExprI32Sub, // i32.sub
26+
kExprLocalSet, 0x03, // local.set
27+
kExprGlobalGet, 0x00, // global.get
28+
kExprLocalSet, 0x04, // local.set
29+
kExprI32Const, 0x00, // i32.const
30+
kExprI32Eqz, // i32.eqz
31+
kExprLocalSet, 0x05, // local.set
32+
kExprGlobalGet, 0x00, // global.get
33+
kExprLocalSet, 0x06, // local.set
34+
kExprI32Const, 0x00, // i32.const
35+
kExprI32Const, 0x01, // i32.const
36+
kExprI32Sub, // i32.sub
37+
kExprLocalSet, 0x07, // local.set
38+
kExprBlock, kWasmStmt, // block @45
39+
kExprI32Const, 0x00, // i32.const
40+
kExprIf, kWasmStmt, // if @49
41+
kExprLocalGet, 0x0a, // local.get
42+
kExprLocalSet, 0x08, // local.set
43+
kExprElse, // else @55
44+
kExprNop, // nop
45+
kExprEnd, // end @57
46+
kExprLocalGet, 0x08, // local.get
47+
kExprLocalSet, 0x09, // local.set
48+
kExprLocalGet, 0x09, // local.get
49+
kExprI64Const, 0xff, 0x01, // i64.const
50+
kExprI64Add, // i64.add
51+
kExprDrop, // drop
52+
kExprEnd, // end @69
53+
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // f64.const
54+
kExprEnd, // end @79
55+
]);
56+
builder.instantiate();

0 commit comments

Comments
 (0)