Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wazevo: fuzz, fix ssa.OpcodeInsertlane #1825

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions internal/engine/wazevo/backend/isa/arm64/lower_instr.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,30 +630,36 @@ func (m *machine) LowerInstr(instr *ssa.Instruction) {
rn := m.getOperand_NR(m.compiler.ValueDefinition(x), extModeNone)
rm := m.getOperand_NR(m.compiler.ValueDefinition(y), extModeNone)
rd := operandNR(m.compiler.VRegOf(instr.Return()))
tmpReg := operandNR(m.compiler.AllocateVReg(ssa.TypeV128))

// Initially mov rn to rd.
mov0 := m.allocateInstr()
mov0.asFpuMov128(rd.nr(), rn.nr())
m.insert(mov0)
// Initially mov rn to tmp.
mov1 := m.allocateInstr()
mov1.asFpuMov128(tmpReg.nr(), rn.nr())
m.insert(mov1)

// movToVec and vecMovElement do not clear the remaining bits to zero,
// thus, we can mov rm in-place to rd.
mov := m.allocateInstr()
// thus, we can mov rm in-place to tmp.
mov2 := m.allocateInstr()
switch lane {
case ssa.VecLaneI8x16:
mov.asMovToVec(rd, rm, vecArrangementB, vecIndex(index))
mov2.asMovToVec(tmpReg, rm, vecArrangementB, vecIndex(index))
case ssa.VecLaneI16x8:
mov.asMovToVec(rd, rm, vecArrangementH, vecIndex(index))
mov2.asMovToVec(tmpReg, rm, vecArrangementH, vecIndex(index))
case ssa.VecLaneI32x4:
mov.asMovToVec(rd, rm, vecArrangementS, vecIndex(index))
mov2.asMovToVec(tmpReg, rm, vecArrangementS, vecIndex(index))
case ssa.VecLaneI64x2:
mov.asMovToVec(rd, rm, vecArrangementD, vecIndex(index))
mov2.asMovToVec(tmpReg, rm, vecArrangementD, vecIndex(index))
case ssa.VecLaneF32x4:
mov.asVecMovElement(rd, rm, vecArrangementS, vecIndex(index), vecIndex(0))
mov2.asVecMovElement(tmpReg, rm, vecArrangementS, vecIndex(index), vecIndex(0))
case ssa.VecLaneF64x2:
mov.asVecMovElement(rd, rm, vecArrangementD, vecIndex(index), vecIndex(0))
mov2.asVecMovElement(tmpReg, rm, vecArrangementD, vecIndex(index), vecIndex(0))
}
m.insert(mov)
m.insert(mov2)

// Finally mov tmp to rd.
mov3 := m.allocateInstr()
mov3.asFpuMov128(rd.nr(), tmpReg.nr())
m.insert(mov3)

case ssa.OpcodeSwizzle:
x, y, lane := instr.Arg2WithLane()
Expand Down
16 changes: 16 additions & 0 deletions internal/integration_test/fuzzcases/fuzzcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,19 @@ func Test1823(t *testing.T) {
require.Equal(t, uint64(4671060543367625455), m.Globals[0].ValHi)
})
}

// Test1825 tests that OpcodeInsertlane allocates correctly the temporary registers.
func Test1825(t *testing.T) {
if !platform.CompilerSupported() {
return
}
run(t, func(t *testing.T, r wazero.Runtime) {
mod, err := r.Instantiate(ctx, getWasmBinary(t, "1825"))
require.NoError(t, err)
m := mod.(*wasm.ModuleInstance)
_, err = m.ExportedFunction("").Call(ctx)
require.NoError(t, err)
require.Equal(t, uint64(1099511627775), m.Globals[6].Val)
require.Equal(t, uint64(18446744073709551615), m.Globals[6].ValHi)
})
}
Binary file not shown.
189 changes: 189 additions & 0 deletions internal/integration_test/fuzzcases/testdata/1825.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
(module
(type (;0;) (func (result f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64)))
(type (;1;) (func))
(type (;2;) (func))
(func (;0;) (type 0) (result f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64)
f64.const -nan:0xfffffffffffff (;=NaN;)
f64.const -nan:0xfffffffffffff (;=NaN;)
f64.const -nan:0xfffffffffffff (;=NaN;)
f64.const -nan:0xfffffffffffff (;=NaN;)
f64.const 0x1.72727ffffffffp-397 (;=0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004483097142929414;)
f64.const 0x1.7272727272727p-397 (;=0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004483094640249093;)
f64.const 0x1.f272727272727p-1008 (;=0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007098121730803434;)
f64.const 0x0p+0 (;=0;)
f64.const -nan:0xfff5700000101 (;=NaN;)
f64.const -0x1.7ffffffffffffp+1011 (;=-32916744412762127000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;)
f64.const -nan:0xfffffffffffff (;=NaN;)
f64.const -0x1.fffffffffffffp+864 (;=-246006311446272400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;)
f64.const 0x1.72727272727f4p-397 (;=0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004483094640249234;)
f64.const -nan:0xfffff27272727 (;=NaN;)
f64.const 0x1.7272727ffffffp-397 (;=0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044830946500251875;)
f64.const 0x1.7272727272727p-397 (;=0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004483094640249093;)
)
(func (;2;) (type 0) (result f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64)
v128.const i32x4 0x2e2e2e60 0x00ffffd2 0xffffffff 0xffffffff
f64.const 0x1.fffffffffep-1035
f64x2.replace_lane 0
call 0
f64x2.splat
i32x4.extract_lane 0
ref.null extern
call 0
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
drop
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
drop
global.get 5
i32.xor
global.set 5
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
i64.reinterpret_f64
global.get 4
i64.xor
global.set 4
global.get 6
v128.xor
global.set 6
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
f64.const 0x0p+0 (;=0;)
)
(table (;0;) 1000 1000 externref)
(table (;1;) 996 996 externref)
(memory (;0;) 0 6)
(global (;0;) (mut i32) i32.const 1768515945)
(global (;1;) (mut funcref) ref.func 0)
(global (;2;) (mut f64) f64.const -nan:0xb76ffffffffff (;=NaN;))
(global (;3;) (mut f64) f64.const 0x1.fffffffffep-1035 (;=0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005432309224866;))
(global (;4;) (mut i64) i64.const 0)
(global (;5;) (mut i32) i32.const 0)
(global (;6;) (mut v128) v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
(global (;7;) (mut i32) i32.const 1000)
(export "" (func 1))
)
Loading