Skip to content

Commit a1b4772

Browse files
committed
[JSC] Six-operand MoveConditionallyTest64 should declare its test operands as 64-bit
https://bugs.webkit.org/show_bug.cgi?id=327768 Reviewed by Yusuke Suzuki. The six-operand form of MoveConditionallyTest64 declared its two test operands as U:G:32, while the five-operand form declares them as U:G:64. On x86-64 the register allocator turns `Move %a, %b` into Move32 when every use of %b is 32-bit, so a 64-bit value used only by this instruction lost its upper half, and Select picked the wrong arm when the low 32 bits were zero. Move32 %rdi, %rax MoveConditionallyTest64 NonZero, %rax, %rax, %rsi, %rdx, %rax ARM64 has the same declaration but generates correct code, since only x86-64 narrows Move based on the use width, and spill slots are sized by the larger of the use and def widths. This patch declares them as U:G:64. Tests: JSTests/wasm/stress/omg-select-i64-test-high-bits.js Source/JavaScriptCore/b3/testb3_1.cpp Source/JavaScriptCore/b3/testb3_6.cpp * JSTests/wasm/stress/omg-select-i64-test-high-bits.js: Added. (m.call): * Source/JavaScriptCore/b3/air/AirOpcode.opcodes: * Source/JavaScriptCore/b3/testb3.h: * Source/JavaScriptCore/b3/testb3_1.cpp: (run): * Source/JavaScriptCore/b3/testb3_6.cpp: (testSelectTestHighBits): Canonical link: https://commits.webkit.org/323931@main
1 parent 21f32b5 commit a1b4772

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
const wat = `
5+
(module
6+
(import "m" "call" (func $call))
7+
(func (export "eqz") (param $x i64) (param $a i64) (param $b i64) (result i64)
8+
(call $call)
9+
(select (local.get $a) (local.get $b) (i64.eqz (local.get $x))))
10+
(func (export "and") (param $x i64) (param $y i64) (param $a i64) (param $b i64) (result i64)
11+
(call $call)
12+
(select (local.get $a) (local.get $b) (i64.eqz (i64.and (local.get $x) (local.get $y)))))
13+
)
14+
`;
15+
16+
const instance = await instantiate(wat, { m: { call() { } } });
17+
const { eqz, and } = instance.exports;
18+
19+
for (let i = 0; i < wasmTestLoopCount; ++i) {
20+
assert.eq(eqz(0n, 1n, 2n), 1n);
21+
assert.eq(eqz(42n, 1n, 2n), 2n);
22+
assert.eq(eqz(0x100000000n, 1n, 2n), 2n);
23+
assert.eq(eqz(-0x100000000n, 1n, 2n), 2n);
24+
25+
assert.eq(and(0n, -1n, 1n, 2n), 1n);
26+
assert.eq(and(42n, -1n, 1n, 2n), 2n);
27+
assert.eq(and(0x100000000n, -1n, 1n, 2n), 2n);
28+
assert.eq(and(-1n, 0x100000000n, 1n, 2n), 2n);
29+
assert.eq(and(0x100000000n, 0xffffffffn, 1n, 2n), 1n);
30+
}

‎Source/JavaScriptCore/b3/air/AirOpcode.opcodes‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ BranchNeg32 U:G:32, UZD:G:32 /branch
17231723
ResCond, Tmp, Tmp, Tmp, Tmp
17241724
x86_64: ResCond, Tmp, Imm, Tmp, Tmp
17251725

1726-
64: MoveConditionallyTest64 U:G:32, U:G:32, U:G:32, U:G:Ptr, U:G:Ptr, D:G:Ptr
1726+
64: MoveConditionallyTest64 U:G:32, U:G:64, U:G:64, U:G:Ptr, U:G:Ptr, D:G:Ptr
17271727
ResCond, Tmp, Tmp, Tmp, Tmp, Tmp
17281728
x86_64: ResCond, Tmp, Imm, Tmp, Tmp, Tmp
17291729
arm64: ResCond, Tmp, Tmp, Tmp, ZeroReg, Tmp

‎Source/JavaScriptCore/b3/testb3.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ void testBitAndZeroShiftRightArgImmMask32();
609609
void testBitAndZeroShiftRightArgImmMask64();
610610
void testBasicSelect();
611611
void testSelectTest();
612+
void testSelectTestHighBits();
612613
void testAddWithLeftShift32();
613614
void testAddWithRightShift32();
614615
void testAddWithUnsignedRightShift32();

‎Source/JavaScriptCore/b3/testb3_1.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ void run(const TestConfig* config)
999999

10001000
RUN(testBasicSelect());
10011001
RUN(testSelectTest());
1002+
RUN(testSelectTestHighBits());
10021003
RUN(testSelectCompareDouble());
10031004
RUN_BINARY(testSelectCompareFloat, floatingPointOperands<float>(), floatingPointOperands<float>());
10041005
RUN_BINARY(testSelectCompareFloatToDouble, floatingPointOperands<float>(), floatingPointOperands<float>());

‎Source/JavaScriptCore/b3/testb3_6.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,27 @@ void testSelectTest()
9292
CHECK_EQ(invoke<intptr_t>(*code, 0, 642462, 32533), 32533);
9393
}
9494

95+
void testSelectTestHighBits()
96+
{
97+
Procedure proc;
98+
BasicBlock* root = proc.addBlock();
99+
auto arguments = cCallArgumentValues<int64_t, int64_t, int64_t>(proc, root);
100+
101+
PatchpointValue* patchpoint = root->appendNew<PatchpointValue>(proc, Void, Origin());
102+
patchpoint->clobberLate(RegisterSet(GPRInfo::argumentGPR0));
103+
patchpoint->setGenerator([](CCallHelpers&, const StackmapGenerationParams&) { });
104+
105+
Value* select = root->appendNew<Value>(proc, Select, Origin(), arguments[0], arguments[1], arguments[2]);
106+
root->clearSuccessors();
107+
root->appendNew<Value>(proc, Return, Origin(), select);
108+
109+
auto code = compileProc(proc);
110+
CHECK_EQ(invoke<int64_t>(*code, 42, 1, 2), 1);
111+
CHECK_EQ(invoke<int64_t>(*code, 0x100000000ll, 1, 2), 1);
112+
CHECK_EQ(invoke<int64_t>(*code, 0xffffffff00000000ull, 1, 2), 1);
113+
CHECK_EQ(invoke<int64_t>(*code, 0, 1, 2), 2);
114+
}
115+
95116
void testSelectCompareDouble()
96117
{
97118
Procedure proc;

0 commit comments

Comments
 (0)