Skip to content

[WebAssembly] Add load and store patterns for V8F16. #108119

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

Merged
merged 1 commit into from
Sep 11, 2024
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
4 changes: 4 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
setOperationAction(ISD::STORE, T, Custom);
}
}
if (Subtarget->hasFP16()) {
setOperationAction(ISD::LOAD, MVT::v8f16, Custom);
setOperationAction(ISD::STORE, MVT::v8f16, Custom);
}
if (Subtarget->hasReferenceTypes()) {
// We need custom load and store lowering for both externref, funcref and
// Other. The MVT::Other here represents tables of reference types.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ defm LOAD_V128_A64 :
}

// Def load patterns from WebAssemblyInstrMemory.td for vector types
foreach vec = StdVecs in {
foreach vec = AllVecs in {
defm : LoadPat<vec.vt, load, "LOAD_V128">;
}

Expand Down Expand Up @@ -390,7 +390,7 @@ defm STORE_V128_A64 :
}

// Def store patterns from WebAssemblyInstrMemory.td for vector types
foreach vec = StdVecs in {
foreach vec = AllVecs in {
defm : StorePat<vec.vt, store, "STORE_V128">;
}

Expand Down
22 changes: 21 additions & 1 deletion llvm/test/CodeGen/WebAssembly/half-precision.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+fp16,+simd128 | FileCheck %s
; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+fp16,+simd128 | FileCheck %s

declare float @llvm.wasm.loadf32.f16(ptr)
declare void @llvm.wasm.storef16.f32(float, ptr)
Expand Down Expand Up @@ -308,3 +307,24 @@ define <8 x i16> @trunc_sat_u_v8i16_sat(<8 x half> %x) {
%a = call <8 x i16> @llvm.fptoui.sat.v8i16.v8f16(<8 x half> %x)
ret <8 x i16> %a
}

; ==============================================================================
; Load and Store
; ==============================================================================
define <8 x half> @load_v8f16(ptr %p) {
; CHECK-LABEL: load_v8f16:
; CHECK: .functype load_v8f16 (i32) -> (v128)
; CHECK-NEXT: v128.load $push0=, 0($0)
; CHECK-NEXT: return $pop0
%v = load <8 x half>, ptr %p
ret <8 x half> %v
}

define void @store_v8f16(<8 x half> %v, ptr %p) {
; CHECK-LABEL: store_v8f16:
; CHECK: .functype store_v8f16 (v128, i32) -> ()
; CHECK-NEXT: v128.store 0($1), $0
; CHECK-NEXT: return
store <8 x half> %v , ptr %p
ret void
}
Loading