[clang] [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (PR #109269)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 19 07:09:55 PDT 2024
https://github.com/RKSimon updated https://github.com/llvm/llvm-project/pull/109269
>From 97dd8d7e892203e6073ebab271967e743fe194fa Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Thu, 19 Sep 2024 11:37:46 +0100
Subject: [PATCH] [clang][wasm] Replace the target integer add saturate
intrinsics with the equivalent generic `__builtin_elementwise_add_sat`
intrinsics
---
.../clang/Basic/BuiltinsWebAssembly.def | 5 ----
clang/lib/CodeGen/CGBuiltin.cpp | 12 --------
clang/lib/Headers/wasm_simd128.h | 8 ++---
clang/test/CodeGen/builtins-wasm.c | 30 +------------------
4 files changed, 5 insertions(+), 50 deletions(-)
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index be9ba7599fe5af..3e2b9477261f12 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -68,11 +68,6 @@ TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", "nontrappi
// SIMD builtins
TARGET_BUILTIN(__builtin_wasm_swizzle_i8x16, "V16ScV16ScV16Sc", "nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_add_sat_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_add_sat_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_add_sat_s_i16x8, "V8sV8sV8s", "nc", "simd128")
-TARGET_BUILTIN(__builtin_wasm_add_sat_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
-
TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128")
TARGET_BUILTIN(__builtin_wasm_sub_sat_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i16x8, "V8sV8sV8s", "nc", "simd128")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e2711f1ba70239..a4e0bd844f9b2b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21443,24 +21443,12 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_swizzle);
return Builder.CreateCall(Callee, {Src, Indices});
}
- case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
- case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
- case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
- case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16:
case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: {
unsigned IntNo;
switch (BuiltinID) {
- case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
- case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
- IntNo = Intrinsic::sadd_sat;
- break;
- case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
- case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
- IntNo = Intrinsic::uadd_sat;
- break;
case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
IntNo = Intrinsic::wasm_sub_sat_signed;
diff --git a/clang/lib/Headers/wasm_simd128.h b/clang/lib/Headers/wasm_simd128.h
index 22f0e27ccf756e..91a45d01f5b6fc 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -982,12 +982,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_add(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_add_sat(v128_t __a,
v128_t __b) {
- return (v128_t)__builtin_wasm_add_sat_s_i8x16((__i8x16)__a, (__i8x16)__b);
+ return (v128_t)__builtin_elementwise_add_sat((__i8x16)__a, (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_add_sat(v128_t __a,
v128_t __b) {
- return (v128_t)__builtin_wasm_add_sat_u_i8x16((__u8x16)__a, (__u8x16)__b);
+ return (v128_t)__builtin_elementwise_add_sat((__u8x16)__a, (__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_sub(v128_t __a,
@@ -1068,12 +1068,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_add(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_add_sat(v128_t __a,
v128_t __b) {
- return (v128_t)__builtin_wasm_add_sat_s_i16x8((__i16x8)__a, (__i16x8)__b);
+ return (v128_t)__builtin_elementwise_add_sat((__i16x8)__a, (__i16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_add_sat(v128_t __a,
v128_t __b) {
- return (v128_t)__builtin_wasm_add_sat_u_i16x8((__u16x8)__a, (__u16x8)__b);
+ return (v128_t)__builtin_elementwise_add_sat((__u16x8)__a, (__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_sub(v128_t __a,
diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c
index 2f49b2c3aa4dfd..abb9d1d13a6c80 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -190,37 +190,9 @@ double max_f64(double x, double y) {
// WEBASSEMBLY-NEXT: ret
}
-i8x16 add_sat_s_i8x16(i8x16 x, i8x16 y) {
- return __builtin_wasm_add_sat_s_i8x16(x, y);
- // MISSING-SIMD: error: '__builtin_wasm_add_sat_s_i8x16' needs target feature simd128
- // WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(
- // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
- // WEBASSEMBLY-NEXT: ret
-}
-
-u8x16 add_sat_u_i8x16(u8x16 x, u8x16 y) {
- return __builtin_wasm_add_sat_u_i8x16(x, y);
- // WEBASSEMBLY: call <16 x i8> @llvm.uadd.sat.v16i8(
- // WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
- // WEBASSEMBLY-NEXT: ret
-}
-
-i16x8 add_sat_s_i16x8(i16x8 x, i16x8 y) {
- return __builtin_wasm_add_sat_s_i16x8(x, y);
- // WEBASSEMBLY: call <8 x i16> @llvm.sadd.sat.v8i16(
- // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
- // WEBASSEMBLY-NEXT: ret
-}
-
-u16x8 add_sat_u_i16x8(u16x8 x, u16x8 y) {
- return __builtin_wasm_add_sat_u_i16x8(x, y);
- // WEBASSEMBLY: call <8 x i16> @llvm.uadd.sat.v8i16(
- // WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
- // WEBASSEMBLY-NEXT: ret
-}
-
i8x16 sub_sat_s_i8x16(i8x16 x, i8x16 y) {
return __builtin_wasm_sub_sat_s_i8x16(x, y);
+ // MISSING-SIMD: error: '__builtin_wasm_sub_sat_s_i8x16' needs target feature simd128
// WEBASSEMBLY: call <16 x i8> @llvm.wasm.sub.sat.signed.v16i8(
// WEBASSEMBLY-SAME: <16 x i8> %x, <16 x i8> %y)
// WEBASSEMBLY-NEXT: ret
More information about the cfe-commits
mailing list