Skip to content

Commit eddb823

Browse files
backesCommit Bot
authored andcommitted
Merged: [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. R=​thibaudm@chromium.org (cherry picked from commit 89ca48c) Bug: chromium:1146861 Change-Id: I96c4985fb8ff710b98e009e457444fc8804bce58 No-Try: true No-Presubmit: true No-Tree-Checks: true Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2584242 Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/branch-heads/8.6@{#50} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent 8af6c93 commit eddb823

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
@@ -138,6 +138,8 @@ template <void (Assembler::*op)(Register, Register, const Operand&, SBit,
138138
SBit, Condition)>
139139
inline void I64BinopI(LiftoffAssembler* assm, LiftoffRegister dst,
140140
LiftoffRegister lhs, int32_t imm) {
141+
// The compiler allocated registers such that either {dst == lhs} or there is
142+
// no overlap between the two.
141143
DCHECK_NE(dst.low_gp(), lhs.high_gp());
142144
(assm->*op)(dst.low_gp(), lhs.low_gp(), Operand(imm), SetCC, al);
143145
// 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
@@ -1421,31 +1421,19 @@ template <void (Assembler::*op)(Register, const Immediate&),
14211421
void (Assembler::*op_with_carry)(Register, int32_t)>
14221422
inline void OpWithCarryI(LiftoffAssembler* assm, LiftoffRegister dst,
14231423
LiftoffRegister lhs, int32_t imm) {
1424-
// First, compute the low half of the result, potentially into a temporary dst
1425-
// register if {dst.low_gp()} equals any register we need to
1426-
// keep alive for computing the upper half.
1427-
LiftoffRegList keep_alive = LiftoffRegList::ForRegs(lhs.high_gp());
1428-
Register dst_low = keep_alive.has(dst.low_gp())
1429-
? assm->GetUnusedRegister(kGpReg, keep_alive).gp()
1430-
: dst.low_gp();
1431-
1432-
if (dst_low != lhs.low_gp()) assm->mov(dst_low, lhs.low_gp());
1433-
(assm->*op)(dst_low, Immediate(imm));
1424+
// The compiler allocated registers such that either {dst == lhs} or there is
1425+
// no overlap between the two.
1426+
DCHECK_NE(dst.low_gp(), lhs.high_gp());
14341427

1435-
// Now compute the upper half, while keeping alive the previous result.
1436-
keep_alive = LiftoffRegList::ForRegs(dst_low);
1437-
Register dst_high = keep_alive.has(dst.high_gp())
1438-
? assm->GetUnusedRegister(kGpReg, keep_alive).gp()
1439-
: dst.high_gp();
1428+
// First, compute the low half of the result.
1429+
if (dst.low_gp() != lhs.low_gp()) assm->mov(dst.low_gp(), lhs.low_gp());
1430+
(assm->*op)(dst.low_gp(), Immediate(imm));
14401431

1441-
if (dst_high != lhs.high_gp()) assm->mov(dst_high, lhs.high_gp());
1432+
// Now compute the upper half.
1433+
if (dst.high_gp() != lhs.high_gp()) assm->mov(dst.high_gp(), lhs.high_gp());
14421434
// Top half of the immediate sign extended, either 0 or -1.
14431435
int32_t sign_extend = imm < 0 ? -1 : 0;
1444-
(assm->*op_with_carry)(dst_high, sign_extend);
1445-
1446-
// If necessary, move result into the right registers.
1447-
LiftoffRegister tmp_result = LiftoffRegister::ForPair(dst_low, dst_high);
1448-
if (tmp_result != dst) assm->Move(dst, tmp_result, kWasmI64);
1436+
(assm->*op_with_carry)(dst.high_gp(), sign_extend);
14491437
}
14501438
} // namespace liftoff
14511439

src/wasm/baseline/liftoff-compiler.cc

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

12031203
LiftoffRegister lhs = __ PopToRegister();
1204+
// Either reuse {lhs} for {dst}, or choose a register (pair) which does
1205+
// not overlap, for easier code generation.
1206+
LiftoffRegList pinned = LiftoffRegList::ForRegs(lhs);
12041207
LiftoffRegister dst = src_rc == result_rc
1205-
? __ GetUnusedRegister(result_rc, {lhs}, {})
1206-
: __ GetUnusedRegister(result_rc, {});
1208+
? __ GetUnusedRegister(result_rc, {lhs}, pinned)
1209+
: __ GetUnusedRegister(result_rc, pinned);
12071210

12081211
CallEmitFn(fnImm, dst, lhs, imm);
12091212
__ 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)