[WebAssembly] __builtin_wasm_replace_lane_* builtins

Summary: Depends on D52852.

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

Differential Revision: https://reviews.llvm.org/D52856

llvm-svn: 343835
This commit is contained in:
Thomas Lively 2018-10-05 00:58:07 +00:00
parent d6792c0c28
commit a347436f09
3 changed files with 73 additions and 0 deletions

View File

@ -49,4 +49,11 @@ BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
#undef BUILTIN

View File

@ -12474,6 +12474,34 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
llvm_unreachable("unexpected builtin ID");
}
}
case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
case WebAssembly::BI__builtin_wasm_replace_lane_i16x8:
case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
llvm::APSInt LaneConst;
if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
llvm_unreachable("Constant arg isn't actually constant?");
Value *Vec = EmitScalarExpr(E->getArg(0));
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
Value *Val = EmitScalarExpr(E->getArg(2));
switch (BuiltinID) {
case WebAssembly::BI__builtin_wasm_replace_lane_i8x16:
case WebAssembly::BI__builtin_wasm_replace_lane_i16x8: {
llvm::Type *ElemType = ConvertType(E->getType())->getVectorElementType();
Value *Trunc = Builder.CreateTrunc(Val, ElemType);
return Builder.CreateInsertElement(Vec, Trunc, Lane);
}
case WebAssembly::BI__builtin_wasm_replace_lane_i32x4:
case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
case WebAssembly::BI__builtin_wasm_replace_lane_f64x2:
return Builder.CreateInsertElement(Vec, Val, Lane);
default:
llvm_unreachable("unexpected builtin ID");
}
}
default:
return nullptr;

View File

@ -134,3 +134,41 @@ double f18(f64x2 v) {
// WEBASSEMBLY: extractelement <2 x double> %v, i32 1
// WEBASSEMBLY-NEXT: ret
}
i8x16 f19(i8x16 v, int x) {
return __builtin_wasm_replace_lane_i8x16(v, 13, x);
// WEBASSEMBLY: trunc i32 %x to i8
// WEBASSEMBLY-NEXT: insertelement <16 x i8> %v, i8 %{{.*}}, i32 13
// WEBASSEMBLY-NEXT: ret
}
i16x8 f20(i16x8 v, int x) {
return __builtin_wasm_replace_lane_i16x8(v, 7, x);
// WEBASSEMBLY: trunc i32 %x to i16
// WEBASSEMBLY-NEXT: insertelement <8 x i16> %v, i16 %{{.*}}, i32 7
// WEBASSEMBLY-NEXT: ret
}
i32x4 f21(i32x4 v, int x) {
return __builtin_wasm_replace_lane_i32x4(v, 3, x);
// WEBASSEMBLY: insertelement <4 x i32> %v, i32 %x, i32 3
// WEBASSEMBLY-NEXT: ret
}
i64x2 f22(i64x2 v, long long x) {
return __builtin_wasm_replace_lane_i64x2(v, 1, x);
// WEBASSEMBLY: insertelement <2 x i64> %v, i64 %x, i32 1
// WEBASSEMBLY-NEXT: ret
}
f32x4 f23(f32x4 v, float x) {
return __builtin_wasm_replace_lane_f32x4(v, 3, x);
// WEBASSEMBLY: insertelement <4 x float> %v, float %x, i32 3
// WEBASSEMBLY-NEXT: ret
}
f64x2 f24(f64x2 v, double x) {
return __builtin_wasm_replace_lane_f64x2(v, 1, x);
// WEBASSEMBLY: insertelement <2 x double> %v, double %x, i32 1
// WEBASSEMBLY-NEXT: ret
}