Author: Simon Pilgrim Date: 2024-09-20T11:49:31+01:00 New Revision: 2c90eb990af176f2b57baecd2920481243845bb9
URL: https://github.com/llvm/llvm-project/commit/2c90eb990af176f2b57baecd2920481243845bb9 DIFF: https://github.com/llvm/llvm-project/commit/2c90eb990af176f2b57baecd2920481243845bb9.diff LOG: [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (#109269) Noticed while working on #109160 I've left out the sub_sat intrinsics for now - not sure about the history behind them using Intrinsic::wasm_sub_sat_* instead of Intrinsic::*sub_sat Added: Modified: clang/include/clang/Basic/BuiltinsWebAssembly.def clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/wasm_simd128.h clang/test/CodeGen/builtins-wasm.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 6a24c9704eb876..90441a5d500120 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 2c4e872b9d7e97..3d1138b7773853 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 bd160bcc9b6964..b1bef7097800b9 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 8677e12032bba1..ff3fe27a29345a 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits