Skip to content

Commit a8a9a7f

Browse files
authored
[WebAssembly] Fix inline assembly with vector types (#146574)
This commit fixes using inline assembly with v128 results. Previously this failed with an internal assertion about a failure to legalize a `CopyFromReg` where the source register was typed `v8f16`. It looks like the type used for the destination register was whatever was listed first in the `def V128 : WebAssemblyRegClass` listing, so the types were shuffled around to have a default-supported type. A small test was added as well which failed to generate previously and should now pass in generation. This test passed on LLVM 18 additionally and regressed by accident in #93228 which was first included in LLVM 19.
1 parent 2a702cd commit a8a9a7f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def I32 : WebAssemblyRegClass<[i32], 32, (add FP32, SP32, I32_0)>;
6464
def I64 : WebAssemblyRegClass<[i64], 64, (add FP64, SP64, I64_0)>;
6565
def F32 : WebAssemblyRegClass<[f32], 32, (add F32_0)>;
6666
def F64 : WebAssemblyRegClass<[f64], 64, (add F64_0)>;
67-
def V128 : WebAssemblyRegClass<[v8f16, v4f32, v2f64, v2i64, v4i32, v16i8,
68-
v8i16],
67+
def V128 : WebAssemblyRegClass<[v2i64, v4i32, v16i8, v8i16,
68+
v8f16, v4f32, v2f64],
6969
128, (add V128_0)>;
7070
def FUNCREF : WebAssemblyRegClass<[funcref], 0, (add FUNCREF_0)>;
7171
def EXTERNREF : WebAssemblyRegClass<[externref], 0, (add EXTERNREF_0)>;

llvm/test/CodeGen/WebAssembly/inline-asm.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,18 @@ entry:
129129
ret i32 %ret
130130
}
131131

132+
; CHECK-LABEL: v128_load
133+
; CHECK: local.get 0
134+
; CHECK-NEXT: v128.load 0
135+
; CHECK-NEXT: local.set 1
136+
define <4 x i32> @v128_load(ptr %v) #1 {
137+
entry:
138+
%0 = tail call <4 x i32> asm "local.get $1\0Av128.load 0\0Alocal.set $0", "=r,r"(ptr %v)
139+
ret <4 x i32> %0
140+
}
141+
132142
attributes #0 = { nounwind }
143+
attributes #1 = { "target-features"="+simd128" }
133144

134145
!0 = !{i32 47}
135146
!1 = !{i32 145}

0 commit comments

Comments
 (0)