Skip to content

Commit 2a9208b

Browse files
authored
[WebAssembly] Change F16x8 extract lane to require constant integer. (#108116)
Building with no optimizations resulted in failures since the lane constant wasn't a constant in LLVM IR.
1 parent ae0ed3d commit 2a9208b

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
209209
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "fp16")
210210
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "fp16")
211211
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "fp16")
212-
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "fp16")
213-
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "fp16")
212+
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hIi", "nc", "fp16")
213+
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hIif", "nc", "fp16")
214214

215215
// Reference Types builtins
216216
// Some builtins are custom type-checked - see 't' as part of the third argument,

clang/lib/Headers/wasm_simd128.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,18 +1888,17 @@ static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_splat(float __a) {
18881888
return (v128_t)__builtin_wasm_splat_f16x8(__a);
18891889
}
18901890

1891-
static __inline__ float __FP16_FN_ATTRS wasm_f16x8_extract_lane(v128_t __a,
1892-
int __i)
1893-
__REQUIRE_CONSTANT(__i) {
1894-
return __builtin_wasm_extract_lane_f16x8((__f16x8)__a, __i);
1895-
}
1891+
#ifdef __wasm_fp16__
1892+
// TODO Replace the following macros with regular C functions and use normal
1893+
// target-independent vector code like the other replace/extract instructions.
18961894

1897-
static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_replace_lane(v128_t __a,
1898-
int __i,
1899-
float __b)
1900-
__REQUIRE_CONSTANT(__i) {
1901-
return (v128_t)__builtin_wasm_replace_lane_f16x8((__f16x8)__a, __i, __b);
1902-
}
1895+
#define wasm_f16x8_extract_lane(__a, __i) \
1896+
(__builtin_wasm_extract_lane_f16x8((__f16x8)(__a), __i))
1897+
1898+
#define wasm_f16x8_replace_lane(__a, __i, __b) \
1899+
((v128_t)__builtin_wasm_replace_lane_f16x8((__f16x8)(__a), __i, __b))
1900+
1901+
#endif
19031902

19041903
static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_abs(v128_t __a) {
19051904
return (v128_t)__builtin_wasm_abs_f16x8((__f16x8)__a);

clang/test/CodeGen/builtins-wasm.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,16 +834,16 @@ f16x8 splat_f16x8(float a) {
834834
return __builtin_wasm_splat_f16x8(a);
835835
}
836836

837-
float extract_lane_f16x8(f16x8 a, int i) {
838-
// WEBASSEMBLY: %0 = tail call float @llvm.wasm.extract.lane.f16x8(<8 x half> %a, i32 %i)
837+
float extract_lane_f16x8(f16x8 a) {
838+
// WEBASSEMBLY: %0 = tail call float @llvm.wasm.extract.lane.f16x8(<8 x half> %a, i32 7)
839839
// WEBASSEMBLY-NEXT: ret float %0
840-
return __builtin_wasm_extract_lane_f16x8(a, i);
840+
return __builtin_wasm_extract_lane_f16x8(a, 7);
841841
}
842842

843-
f16x8 replace_lane_f16x8(f16x8 a, int i, float v) {
844-
// WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.replace.lane.f16x8(<8 x half> %a, i32 %i, float %v)
843+
f16x8 replace_lane_f16x8(f16x8 a, float v) {
844+
// WEBASSEMBLY: %0 = tail call <8 x half> @llvm.wasm.replace.lane.f16x8(<8 x half> %a, i32 7, float %v)
845845
// WEBASSEMBLY-NEXT: ret <8 x half> %0
846-
return __builtin_wasm_replace_lane_f16x8(a, i, v);
846+
return __builtin_wasm_replace_lane_f16x8(a, 7, v);
847847
}
848848

849849
f16x8 min_f16x8(f16x8 a, f16x8 b) {

0 commit comments

Comments
 (0)