[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
aheejin wrote: I guess you've likely already found it but anyway it's here: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access It's basically "Email Chris". https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/aheejin closed https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
brendandahl wrote: > LGTM % `!HasHalfPrecision` thing > > By the way I guess you can try getting commit access soon? I think it is > still "Send an email to Chris" though... Done, can I get a squash and merge? I'll look into getting commit access. https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/aheejin edited https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/brendandahl updated https://github.com/llvm/llvm-project/pull/93228 >From 28cc678038feefffceba8cbe24349e1885b24c75 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 21 May 2024 21:15:14 + Subject: [PATCH 1/2] [WebAssembly] Implement prototype f16x8.splat instruction. Adds a builtin and intrinsic for the f16x8.splat instruction. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md Note: the current spec has f16x8.splat as opcode 0x123, but this is incorrect and will be changed to 0x120 soon. --- clang/include/clang/Basic/BuiltinsWebAssembly.def | 1 + clang/lib/Basic/Targets/WebAssembly.h | 1 + clang/lib/CodeGen/CGBuiltin.cpp | 5 + clang/test/CodeGen/builtins-wasm.c| 6 ++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 4 .../Utils/WebAssemblyTypeUtilities.cpp| 1 + .../WebAssembly/WebAssemblyISelLowering.cpp | 3 +++ .../Target/WebAssembly/WebAssemblyInstrSIMD.td| 15 +++ .../Target/WebAssembly/WebAssemblyRegisterInfo.td | 5 +++-- llvm/test/CodeGen/WebAssembly/half-precision.ll | 12 ++-- llvm/test/MC/WebAssembly/simd-encodings.s | 3 +++ 11 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 8645cff1e8679..dbe79aa39190d 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -193,6 +193,7 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f" // Half-Precision (fp16) TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision") TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision") +TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision") // Reference Types builtins // Some builtins are custom type-checked - see 't' as part of the third argument, diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 4db97867df607..46416d516b42f 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -90,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { return false; } protected: void getTargetDefines(const LangOptions , diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index ba94bf89e4751..91083c1cfae96 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21230,6 +21230,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32); return Builder.CreateCall(Callee, {Val, Addr}); } + case WebAssembly::BI__builtin_wasm_splat_f16x8: { +Value *Val = EmitScalarExpr(E->getArg(0)); +Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_splat_f16x8); +return Builder.CreateCall(Callee, {Val}); + } case WebAssembly::BI__builtin_wasm_table_get: { assert(E->getArg(0)->getType()->isArrayType()); Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this); diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c index bcb15969de1c5..76c6305d422a2 100644 --- a/clang/test/CodeGen/builtins-wasm.c +++ b/clang/test/CodeGen/builtins-wasm.c @@ -11,6 +11,7 @@ typedef unsigned char u8x16 __attribute((vector_size(16))); typedef unsigned short u16x8 __attribute((vector_size(16))); typedef unsigned int u32x4 __attribute((vector_size(16))); typedef unsigned long long u64x2 __attribute((vector_size(16))); +typedef __fp16 f16x8 __attribute((vector_size(16))); typedef float f32x4 __attribute((vector_size(16))); typedef double f64x2 __attribute((vector_size(16))); @@ -813,6 +814,11 @@ void store_f16_f32(float val, __fp16 *addr) { // WEBASSEMBLY-NEXT: ret } +f16x8 splat_f16x8(float a) { + // WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.splat.f16x8(float %a) + // WEBASSEMBLY-NEXT: ret <8 x half> %0 + return __builtin_wasm_splat_f16x8(a); +} __externref_t externref_null() { return __builtin_wasm_ref_null_extern(); // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern() diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td index 572d334ac9552..c950b33182689 100644 --- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td +++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td @@ -337,6 +337,10 @@ def int_wasm_storef16_f32: [llvm_float_ty, llvm_ptr_ty], [IntrWriteMem, IntrArgMemOnly], "", [SDNPMemOperand]>; +def
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/aheejin approved this pull request. LGTM % `!HasHalfPrecision` thing By the way I guess you can try getting a commit access soon? I think it is still "Send an an email to Chris" though... https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
@@ -90,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { return false; } aheejin wrote: I am not very familiar with the places where the function is used, but `!HasHalfPrecision` seems safer. https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
@@ -90,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { return false; } brendandahl wrote: Yeah, this is what causes clang to start outputting `half` types. I could conditionally enable this with `return !HasHalfPrecision;` instead. Though doing a quick test with scalar `__fp16` in c, the `half` types seems to work correctly regardless of this setting. https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
@@ -90,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { return false; } dschuff wrote: Is this used? https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/brendandahl updated https://github.com/llvm/llvm-project/pull/93228 >From 28cc678038feefffceba8cbe24349e1885b24c75 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 21 May 2024 21:15:14 + Subject: [PATCH] [WebAssembly] Implement prototype f16x8.splat instruction. Adds a builtin and intrinsic for the f16x8.splat instruction. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md Note: the current spec has f16x8.splat as opcode 0x123, but this is incorrect and will be changed to 0x120 soon. --- clang/include/clang/Basic/BuiltinsWebAssembly.def | 1 + clang/lib/Basic/Targets/WebAssembly.h | 1 + clang/lib/CodeGen/CGBuiltin.cpp | 5 + clang/test/CodeGen/builtins-wasm.c| 6 ++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 4 .../Utils/WebAssemblyTypeUtilities.cpp| 1 + .../WebAssembly/WebAssemblyISelLowering.cpp | 3 +++ .../Target/WebAssembly/WebAssemblyInstrSIMD.td| 15 +++ .../Target/WebAssembly/WebAssemblyRegisterInfo.td | 5 +++-- llvm/test/CodeGen/WebAssembly/half-precision.ll | 12 ++-- llvm/test/MC/WebAssembly/simd-encodings.s | 3 +++ 11 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 8645cff1e8679..dbe79aa39190d 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -193,6 +193,7 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f" // Half-Precision (fp16) TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision") TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision") +TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision") // Reference Types builtins // Some builtins are custom type-checked - see 't' as part of the third argument, diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 4db97867df607..46416d516b42f 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -90,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { return false; } protected: void getTargetDefines(const LangOptions , diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index ba94bf89e4751..91083c1cfae96 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21230,6 +21230,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32); return Builder.CreateCall(Callee, {Val, Addr}); } + case WebAssembly::BI__builtin_wasm_splat_f16x8: { +Value *Val = EmitScalarExpr(E->getArg(0)); +Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_splat_f16x8); +return Builder.CreateCall(Callee, {Val}); + } case WebAssembly::BI__builtin_wasm_table_get: { assert(E->getArg(0)->getType()->isArrayType()); Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this); diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c index bcb15969de1c5..76c6305d422a2 100644 --- a/clang/test/CodeGen/builtins-wasm.c +++ b/clang/test/CodeGen/builtins-wasm.c @@ -11,6 +11,7 @@ typedef unsigned char u8x16 __attribute((vector_size(16))); typedef unsigned short u16x8 __attribute((vector_size(16))); typedef unsigned int u32x4 __attribute((vector_size(16))); typedef unsigned long long u64x2 __attribute((vector_size(16))); +typedef __fp16 f16x8 __attribute((vector_size(16))); typedef float f32x4 __attribute((vector_size(16))); typedef double f64x2 __attribute((vector_size(16))); @@ -813,6 +814,11 @@ void store_f16_f32(float val, __fp16 *addr) { // WEBASSEMBLY-NEXT: ret } +f16x8 splat_f16x8(float a) { + // WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.splat.f16x8(float %a) + // WEBASSEMBLY-NEXT: ret <8 x half> %0 + return __builtin_wasm_splat_f16x8(a); +} __externref_t externref_null() { return __builtin_wasm_ref_null_extern(); // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern() diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td index 572d334ac9552..c950b33182689 100644 --- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td +++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td @@ -337,6 +337,10 @@ def int_wasm_storef16_f32: [llvm_float_ty, llvm_ptr_ty], [IntrWriteMem, IntrArgMemOnly], "", [SDNPMemOperand]>; +def
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff dd2d132fb3521f37f44656edd65cca75430c251e 002e33294cae26796ca79a66dbd275f3e26807d2 -- clang/lib/Basic/Targets/WebAssembly.h clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/builtins-wasm.c llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 63f4e72a9c..46416d516b 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -90,9 +90,7 @@ public: StringRef getABI() const override; bool setABI(const std::string ) override; - bool useFP16ConversionIntrinsics() const override { -return false; - } + bool useFP16ConversionIntrinsics() const override { return false; } protected: void getTargetDefines(const LangOptions , `` https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
brendandahl wrote: cc @aheejin @dschuff As mentioned in the meeting, it looks like it will be a lot more work to get half value's working with normal patterns, so for now I'll stick to just built-ins and intrinsics. https://github.com/llvm/llvm-project/pull/93228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
llvmbot wrote: @llvm/pr-subscribers-mc Author: Brendan Dahl (brendandahl) Changes Adds a builtin and intrinsic for the f16x8.splat instruction. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md Note: the current spec has f16x8.splat as opcode 0x123, but this is incorrect and will be changed to 0x120 soon. --- Full diff: https://github.com/llvm/llvm-project/pull/93228.diff 11 Files Affected: - (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+1) - (modified) clang/lib/Basic/Targets/WebAssembly.h (+3) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+5) - (modified) clang/test/CodeGen/builtins-wasm.c (+6) - (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+4) - (modified) llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp (+1) - (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+3) - (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td (+15) - (modified) llvm/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td (+3-2) - (modified) llvm/test/CodeGen/WebAssembly/half-precision.ll (+10-2) - (modified) llvm/test/MC/WebAssembly/simd-encodings.s (+3) ``diff diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 8645cff1e8679..dbe79aa39190d 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -193,6 +193,7 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f" // Half-Precision (fp16) TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision") TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision") +TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision") // Reference Types builtins // Some builtins are custom type-checked - see 't' as part of the third argument, diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 4db97867df607..63f4e72a9c2de 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -90,6 +90,9 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { +return false; + } protected: void getTargetDefines(const LangOptions , diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index ba94bf89e4751..91083c1cfae96 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21230,6 +21230,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32); return Builder.CreateCall(Callee, {Val, Addr}); } + case WebAssembly::BI__builtin_wasm_splat_f16x8: { +Value *Val = EmitScalarExpr(E->getArg(0)); +Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_splat_f16x8); +return Builder.CreateCall(Callee, {Val}); + } case WebAssembly::BI__builtin_wasm_table_get: { assert(E->getArg(0)->getType()->isArrayType()); Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this); diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c index bcb15969de1c5..76c6305d422a2 100644 --- a/clang/test/CodeGen/builtins-wasm.c +++ b/clang/test/CodeGen/builtins-wasm.c @@ -11,6 +11,7 @@ typedef unsigned char u8x16 __attribute((vector_size(16))); typedef unsigned short u16x8 __attribute((vector_size(16))); typedef unsigned int u32x4 __attribute((vector_size(16))); typedef unsigned long long u64x2 __attribute((vector_size(16))); +typedef __fp16 f16x8 __attribute((vector_size(16))); typedef float f32x4 __attribute((vector_size(16))); typedef double f64x2 __attribute((vector_size(16))); @@ -813,6 +814,11 @@ void store_f16_f32(float val, __fp16 *addr) { // WEBASSEMBLY-NEXT: ret } +f16x8 splat_f16x8(float a) { + // WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.splat.f16x8(float %a) + // WEBASSEMBLY-NEXT: ret <8 x half> %0 + return __builtin_wasm_splat_f16x8(a); +} __externref_t externref_null() { return __builtin_wasm_ref_null_extern(); // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern() diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td index 572d334ac9552..c950b33182689 100644 --- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td +++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td @@ -337,6 +337,10 @@ def int_wasm_storef16_f32: [llvm_float_ty, llvm_ptr_ty], [IntrWriteMem, IntrArgMemOnly], "", [SDNPMemOperand]>; +def int_wasm_splat_f16x8: + DefaultAttrsIntrinsic<[llvm_v8f16_ty], +[llvm_float_ty], +
[clang] [llvm] [WebAssembly] Implement prototype f16x8.splat instruction. (PR #93228)
https://github.com/brendandahl created https://github.com/llvm/llvm-project/pull/93228 Adds a builtin and intrinsic for the f16x8.splat instruction. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md Note: the current spec has f16x8.splat as opcode 0x123, but this is incorrect and will be changed to 0x120 soon. >From 002e33294cae26796ca79a66dbd275f3e26807d2 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 21 May 2024 21:15:14 + Subject: [PATCH] [WebAssembly] Implement prototype f16x8.splat instruction. Adds a builtin and intrinsic for the f16x8.splat instruction. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md Note: the current spec has f16x8.splat as opcode 0x123, but this is incorrect and will be changed to 0x120 soon. --- clang/include/clang/Basic/BuiltinsWebAssembly.def | 1 + clang/lib/Basic/Targets/WebAssembly.h | 3 +++ clang/lib/CodeGen/CGBuiltin.cpp | 5 + clang/test/CodeGen/builtins-wasm.c| 6 ++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 4 .../Utils/WebAssemblyTypeUtilities.cpp| 1 + .../WebAssembly/WebAssemblyISelLowering.cpp | 3 +++ .../Target/WebAssembly/WebAssemblyInstrSIMD.td| 15 +++ .../Target/WebAssembly/WebAssemblyRegisterInfo.td | 5 +++-- llvm/test/CodeGen/WebAssembly/half-precision.ll | 12 ++-- llvm/test/MC/WebAssembly/simd-encodings.s | 3 +++ 11 files changed, 54 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 8645cff1e8679..dbe79aa39190d 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -193,6 +193,7 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f" // Half-Precision (fp16) TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision") TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision") +TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision") // Reference Types builtins // Some builtins are custom type-checked - see 't' as part of the third argument, diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 4db97867df607..63f4e72a9c2de 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -90,6 +90,9 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { StringRef getABI() const override; bool setABI(const std::string ) override; + bool useFP16ConversionIntrinsics() const override { +return false; + } protected: void getTargetDefines(const LangOptions , diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index ba94bf89e4751..91083c1cfae96 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21230,6 +21230,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32); return Builder.CreateCall(Callee, {Val, Addr}); } + case WebAssembly::BI__builtin_wasm_splat_f16x8: { +Value *Val = EmitScalarExpr(E->getArg(0)); +Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_splat_f16x8); +return Builder.CreateCall(Callee, {Val}); + } case WebAssembly::BI__builtin_wasm_table_get: { assert(E->getArg(0)->getType()->isArrayType()); Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this); diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c index bcb15969de1c5..76c6305d422a2 100644 --- a/clang/test/CodeGen/builtins-wasm.c +++ b/clang/test/CodeGen/builtins-wasm.c @@ -11,6 +11,7 @@ typedef unsigned char u8x16 __attribute((vector_size(16))); typedef unsigned short u16x8 __attribute((vector_size(16))); typedef unsigned int u32x4 __attribute((vector_size(16))); typedef unsigned long long u64x2 __attribute((vector_size(16))); +typedef __fp16 f16x8 __attribute((vector_size(16))); typedef float f32x4 __attribute((vector_size(16))); typedef double f64x2 __attribute((vector_size(16))); @@ -813,6 +814,11 @@ void store_f16_f32(float val, __fp16 *addr) { // WEBASSEMBLY-NEXT: ret } +f16x8 splat_f16x8(float a) { + // WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.splat.f16x8(float %a) + // WEBASSEMBLY-NEXT: ret <8 x half> %0 + return __builtin_wasm_splat_f16x8(a); +} __externref_t externref_null() { return __builtin_wasm_ref_null_extern(); // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern() diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td index