Skip to content

Commit 020ff45

Browse files
tlivelymemfrob
authored andcommitted
[WebAssembly] Codegen for v128.storeX_lane instructions
Replace the experimental clang builtins and LLVM intrinsics for these instructions with normal codegen patterns. Resolves PR50435. Differential Revision: https://reviews.llvm.org/D106019
1 parent d710f14 commit 020ff45

File tree

11 files changed

+418
-275
lines changed

11 files changed

+418
-275
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,5 @@ TARGET_BUILTIN(__builtin_wasm_trunc_sat_zero_u_f64x2_i32x4, "V4UiV2d", "nc", "si
195195
TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4iiC*", "n", "simd128")
196196
TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLiC*", "n", "simd128")
197197

198-
TARGET_BUILTIN(__builtin_wasm_store8_lane, "vSc*V16ScIi", "n", "simd128")
199-
TARGET_BUILTIN(__builtin_wasm_store16_lane, "vs*V8sIi", "n", "simd128")
200-
TARGET_BUILTIN(__builtin_wasm_store32_lane, "vi*V4iIi", "n", "simd128")
201-
TARGET_BUILTIN(__builtin_wasm_store64_lane, "vLLi*V2LLiIi", "n", "simd128")
202-
203198
#undef BUILTIN
204199
#undef TARGET_BUILTIN

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17776,36 +17776,6 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1777617776
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_load64_zero);
1777717777
return Builder.CreateCall(Callee, {Ptr});
1777817778
}
17779-
case WebAssembly::BI__builtin_wasm_store8_lane:
17780-
case WebAssembly::BI__builtin_wasm_store16_lane:
17781-
case WebAssembly::BI__builtin_wasm_store32_lane:
17782-
case WebAssembly::BI__builtin_wasm_store64_lane: {
17783-
Value *Ptr = EmitScalarExpr(E->getArg(0));
17784-
Value *Vec = EmitScalarExpr(E->getArg(1));
17785-
Optional<llvm::APSInt> LaneIdxConst =
17786-
E->getArg(2)->getIntegerConstantExpr(getContext());
17787-
assert(LaneIdxConst && "Constant arg isn't actually constant?");
17788-
Value *LaneIdx = llvm::ConstantInt::get(getLLVMContext(), *LaneIdxConst);
17789-
unsigned IntNo;
17790-
switch (BuiltinID) {
17791-
case WebAssembly::BI__builtin_wasm_store8_lane:
17792-
IntNo = Intrinsic::wasm_store8_lane;
17793-
break;
17794-
case WebAssembly::BI__builtin_wasm_store16_lane:
17795-
IntNo = Intrinsic::wasm_store16_lane;
17796-
break;
17797-
case WebAssembly::BI__builtin_wasm_store32_lane:
17798-
IntNo = Intrinsic::wasm_store32_lane;
17799-
break;
17800-
case WebAssembly::BI__builtin_wasm_store64_lane:
17801-
IntNo = Intrinsic::wasm_store64_lane;
17802-
break;
17803-
default:
17804-
llvm_unreachable("unexpected builtin ID");
17805-
}
17806-
Function *Callee = CGM.getIntrinsic(IntNo);
17807-
return Builder.CreateCall(Callee, {Ptr, Vec, LaneIdx});
17808-
}
1780917779
case WebAssembly::BI__builtin_wasm_shuffle_i8x16: {
1781017780
Value *Ops[18];
1781117781
size_t OpIdx = 0;

clang/lib/Headers/wasm_simd128.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,48 @@ static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store(void *__mem,
223223
((struct __wasm_v128_store_struct *)__mem)->__v = __a;
224224
}
225225

226-
#define wasm_v128_store8_lane(__ptr, __vec, __i) \
227-
(__builtin_wasm_store8_lane((signed char *)(__ptr), (__i8x16)(__vec), (__i)))
226+
static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store8_lane(void *__mem,
227+
v128_t __vec,
228+
int __i)
229+
__REQUIRE_CONSTANT(__i) {
230+
struct __wasm_v128_store8_lane_struct {
231+
int8_t __v;
232+
} __attribute__((__packed__, __may_alias__));
233+
((struct __wasm_v128_store8_lane_struct *)__mem)->__v = ((__i8x16)__vec)[__i];
234+
}
228235

229-
#define wasm_v128_store16_lane(__ptr, __vec, __i) \
230-
(__builtin_wasm_store16_lane((short *)(__ptr), (__i16x8)(__vec), (__i)))
236+
static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store16_lane(void *__mem,
237+
v128_t __vec,
238+
int __i)
239+
__REQUIRE_CONSTANT(__i) {
240+
struct __wasm_v128_store16_lane_struct {
241+
int16_t __v;
242+
} __attribute__((__packed__, __may_alias__));
243+
((struct __wasm_v128_store16_lane_struct *)__mem)->__v =
244+
((__i16x8)__vec)[__i];
245+
}
231246

232-
#define wasm_v128_store32_lane(__ptr, __vec, __i) \
233-
(__builtin_wasm_store32_lane((int *)(__ptr), (__i32x4)(__vec), (__i)))
247+
static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store32_lane(void *__mem,
248+
v128_t __vec,
249+
int __i)
250+
__REQUIRE_CONSTANT(__i) {
251+
struct __wasm_v128_store32_lane_struct {
252+
int32_t __v;
253+
} __attribute__((__packed__, __may_alias__));
254+
((struct __wasm_v128_store32_lane_struct *)__mem)->__v =
255+
((__i32x4)__vec)[__i];
256+
}
234257

235-
#define wasm_v128_store64_lane(__ptr, __vec, __i) \
236-
(__builtin_wasm_store64_lane((long long int *)(__ptr), (__i64x2)(__vec), \
237-
(__i)))
258+
static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store64_lane(void *__mem,
259+
v128_t __vec,
260+
int __i)
261+
__REQUIRE_CONSTANT(__i) {
262+
struct __wasm_v128_store64_lane_struct {
263+
int64_t __v;
264+
} __attribute__((__packed__, __may_alias__));
265+
((struct __wasm_v128_store64_lane_struct *)__mem)->__v =
266+
((__i64x2)__vec)[__i];
267+
}
238268

239269
static __inline__ v128_t __DEFAULT_FN_ATTRS
240270
wasm_i8x16_make(int8_t __c0, int8_t __c1, int8_t __c2, int8_t __c3, int8_t __c4,

clang/test/CodeGen/builtins-wasm.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,34 +284,6 @@ f64x2 replace_lane_f64x2(f64x2 v, double x) {
284284
// WEBASSEMBLY-NEXT: ret
285285
}
286286

287-
void store8_lane(signed char *p, i8x16 v) {
288-
__builtin_wasm_store8_lane(p, v, 0);
289-
// WEBASSEMBLY: call void @llvm.wasm.store8.lane(
290-
// WEBASSEMBLY-SAME: i8* %p, <16 x i8> %v, i32 0)
291-
// WEBASSEMBLY-NEXT: ret
292-
}
293-
294-
void store16_lane(short *p, i16x8 v) {
295-
__builtin_wasm_store16_lane(p, v, 0);
296-
// WEBASSEMBLY: call void @llvm.wasm.store16.lane(
297-
// WEBASSEMBLY-SAME: i16* %p, <8 x i16> %v, i32 0)
298-
// WEBASSEMBLY-NEXT: ret
299-
}
300-
301-
void store32_lane(int *p, i32x4 v) {
302-
__builtin_wasm_store32_lane(p, v, 0);
303-
// WEBASSEMBLY: call void @llvm.wasm.store32.lane(
304-
// WEBASSEMBLY-SAME: i32* %p, <4 x i32> %v, i32 0)
305-
// WEBASSEMBLY-NEXT: ret
306-
}
307-
308-
void store64_lane(long long *p, i64x2 v) {
309-
__builtin_wasm_store64_lane(p, v, 0);
310-
// WEBASSEMBLY: call void @llvm.wasm.store64.lane(
311-
// WEBASSEMBLY-SAME: i64* %p, <2 x i64> %v, i32 0)
312-
// WEBASSEMBLY-NEXT: ret
313-
}
314-
315287
i8x16 add_sat_s_i8x16(i8x16 x, i8x16 y) {
316288
return __builtin_wasm_add_sat_s_i8x16(x, y);
317289
// WEBASSEMBLY: call <16 x i8> @llvm.sadd.sat.v16i8(

0 commit comments

Comments
 (0)