Skip to content

Commit 600fe6f

Browse files
committed
[Wasm] JSToWasm IC needs assume no tag registers consistently
https://bugs.webkit.org/show_bug.cgi?id=329421 rdar://191643874 Reviewed by Yusuke Suzuki. When 325503@main stopped materializing tag registers in jsToWasmICEntrypoint, the f32/f64 argument case still called branchIfInt32 and unboxDouble in HaveTagRegisters mode. If wasm leaves an i64 in numberTagRegister and a JS tail call jumps into the IC, Int32 arguments get unboxed as doubles and come out as NaN (and doubles get converted as Int32s). This patch adds DoNotHaveTagRegisters for both, and uses a separate result register because unboxDouble overwrites its result before it reads the input without tags. Also, switch jitAssertIsJSDouble to use constants rather than assume the state of the tag registers. This broke when passing DoNotHaveTagRegisters to unboxDouble. Tests: JSTests/stress/wasm-js-to-wasm-ic-materializes-tag-registers.js: * JSTests/stress/wasm-js-to-wasm-ic-materializes-tag-registers.js: * Source/JavaScriptCore/jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::jitAssertIsJSDouble): * Source/JavaScriptCore/wasm/js/JSToWasm.cpp: (JSC::Wasm::RTT::jsToWasmICEntrypoint const): Canonical link: https://commits.webkit.org/325593@main
1 parent e865968 commit 600fe6f

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎JSTests/stress/wasm-js-to-wasm-ic-materializes-tag-registers.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function section(id, content) {
3636
return [id, ...leb(content.length), ...content];
3737
}
3838

39-
const I64 = 0x7e, EXTERNREF = 0x6f, FUNCREF = 0x70;
39+
const I64 = 0x7e, F32 = 0x7d, F64 = 0x7c, EXTERNREF = 0x6f, FUNCREF = 0x70;
4040

4141
// (func (export "callee") (param T) (result T) local.get 0)
4242
function buildCallee(type) {
@@ -139,3 +139,23 @@ test("funcref", FUNCREF, someFuncref, [
139139
[13.37, invalidFuncref],
140140
[true, invalidFuncref],
141141
]);
142+
143+
// The f32/f64 arms: branchIfInt32 picks int32 vs. double conversion, then unboxDouble.
144+
// With a stale numberTagRegister, doubles are converted as int32s and int32s are unboxed as doubles.
145+
test("f32", F32, 0.5, [
146+
[0, "0"],
147+
[1, "1"],
148+
[2, "2"],
149+
[-7, "-7"],
150+
[1.5, "1.5"],
151+
[-2.25, "-2.25"],
152+
]);
153+
154+
test("f64", F64, 0.5, [
155+
[0, "0"],
156+
[1, "1"],
157+
[2, "2"],
158+
[-7, "-7"],
159+
[1.5, "1.5"],
160+
[13.37, "13.37"],
161+
]);

‎Source/JavaScriptCore/jit/AssemblyHelpers.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ void AssemblyHelpers::jitAssertIsJSDouble(GPRReg gpr)
174174
if (!Options::useJITAsserts())
175175
return;
176176
JIT_COMMENT(*this, "ASSERT is JS boxed double (non-int32 number)");
177-
Jump checkJSInt32 = branch64(AboveOrEqual, gpr, GPRInfo::numberTagRegister);
178-
Jump checkJSNumber = branchTest64(MacroAssembler::NonZero, gpr, GPRInfo::numberTagRegister);
177+
Jump checkJSInt32 = branch64(AboveOrEqual, gpr, TrustedImm64(JSValue::NumberTag));
178+
Jump checkJSNumber = branchTest64(MacroAssembler::NonZero, gpr, TrustedImm64(JSValue::NumberTag));
179179
checkJSInt32.link(this);
180180
abortWithReason(AHIsNotJSDouble);
181181
checkJSNumber.link(this);

‎Source/JavaScriptCore/wasm/js/JSToWasm.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ CodePtr<JSEntryPtrTag> RTT::jsToWasmICEntrypoint() const
621621

622622
jit.loadValue(jsParam, scratchGPR);
623623
slowPath.append(jit.branchIfNotNumber(scratchGPR, DoNotHaveTagRegisters));
624-
auto isInt32 = jit.branchIfInt32(scratchGPR);
625-
jit.unboxDouble(scratchGPR, scratchGPR, scratchFPR);
624+
auto isInt32 = jit.branchIfInt32(scratchGPR, DoNotHaveTagRegisters);
625+
jit.unboxDouble(scratchGPR, stackLimitGPR, scratchFPR, DoNotHaveTagRegisters);
626626
if (argumentType(i).isF32())
627627
jit.convertDoubleToFloat(scratchFPR, scratchFPR);
628628
auto done = jit.jump();

0 commit comments

Comments
 (0)