[WebAssembly] Add prototype relaxed swizzle instructions

Add i8x16 relaxed_swizzle instructions. These are only
exposed as builtins, and require user opt-in.

Differential Revision: https://reviews.llvm.org/D112022
This commit is contained in:
Zhi An Ng 2021-10-19 17:53:04 -07:00 committed by Thomas Lively
parent 320f65ee65
commit 2542bfa43a
7 changed files with 42 additions and 0 deletions

View File

@ -172,5 +172,7 @@ TARGET_BUILTIN(__builtin_wasm_laneselect_i16x8, "V8sV8sV8sV8s", "nc", "relaxed-s
TARGET_BUILTIN(__builtin_wasm_laneselect_i32x4, "V4iV4iV4iV4i", "nc", "relaxed-simd")
TARGET_BUILTIN(__builtin_wasm_laneselect_i64x2, "V2LLiV2LLiV2LLiV2LLi", "nc", "relaxed-simd")
TARGET_BUILTIN(__builtin_wasm_relaxed_swizzle_i8x16, "V16ScV16ScV16Sc", "nc", "relaxed-simd")
#undef BUILTIN
#undef TARGET_BUILTIN

View File

@ -18319,6 +18319,12 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
CGM.getIntrinsic(Intrinsic::wasm_laneselect, A->getType());
return Builder.CreateCall(Callee, {A, B, C});
}
case WebAssembly::BI__builtin_wasm_relaxed_swizzle_i8x16: {
Value *Src = EmitScalarExpr(E->getArg(0));
Value *Indices = EmitScalarExpr(E->getArg(1));
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_relaxed_swizzle);
return Builder.CreateCall(Callee, {Src, Indices});
}
default:
return nullptr;
}

View File

@ -732,3 +732,8 @@ i64x2 laneselect_i64x2(i64x2 a, i64x2 b, i64x2 c) {
// WEBASSEMBLY-SAME: <2 x i64> %a, <2 x i64> %b, <2 x i64> %c)
// WEBASSEMBLY-NEXT: ret
}
i8x16 relaxed_swizzle_i8x16(i8x16 x, i8x16 y) {
return __builtin_wasm_relaxed_swizzle_i8x16(x, y);
// WEBASSEMBLY: call <16 x i8> @llvm.wasm.relaxed.swizzle(<16 x i8> %x, <16 x i8> %y)
}

View File

@ -200,6 +200,11 @@ def int_wasm_laneselect :
[LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
[IntrNoMem, IntrSpeculatable]>;
def int_wasm_relaxed_swizzle :
Intrinsic<[llvm_v16i8_ty],
[llvm_v16i8_ty, llvm_v16i8_ty],
[IntrNoMem, IntrSpeculatable]>;
//===----------------------------------------------------------------------===//
// Thread-local storage intrinsics
//===----------------------------------------------------------------------===//

View File

@ -1361,3 +1361,14 @@ defm "" : SIMDLANESELECT<I8x16, 0xb2>;
defm "" : SIMDLANESELECT<I16x8, 0xb3>;
defm "" : SIMDLANESELECT<I32x4, 0xd2>;
defm "" : SIMDLANESELECT<I64x2, 0xd3>;
//===----------------------------------------------------------------------===//
// Relaxed swizzle
//===----------------------------------------------------------------------===//
defm RELAXED_SWIZZLE :
RELAXED_I<(outs V128:$dst), (ins V128:$src, V128:$mask), (outs), (ins),
[(set (v16i8 V128:$dst),
(int_wasm_relaxed_swizzle (v16i8 V128:$src), (v16i8 V128:$mask)))],
"i8x16.relaxed_swizzle\t$dst, $src, $mask", "i8x16.relaxed_swizzle", 162>;

View File

@ -192,6 +192,16 @@ define <16 x i8> @laneselect_v16i8(<16 x i8> %a, <16 x i8> %b, <16 x i8> %c) {
ret <16 x i8> %v
}
; CHECK-LABEL: relaxed_swizzle_v16i8:
; CHECK-NEXT: .functype relaxed_swizzle_v16i8 (v128, v128) -> (v128){{$}}
; CHECK-NEXT: i8x16.relaxed_swizzle $push[[R:[0-9]+]]=, $0, $1{{$}}
; CHECK-NEXT: return $pop[[R]]{{$}}
declare <16 x i8> @llvm.wasm.relaxed.swizzle(<16 x i8>, <16 x i8>)
define <16 x i8> @relaxed_swizzle_v16i8(<16 x i8> %x, <16 x i8> %y) {
%a = call <16 x i8> @llvm.wasm.relaxed.swizzle(<16 x i8> %x, <16 x i8> %y)
ret <16 x i8> %a
}
; ==============================================================================
; 8 x i16
; ==============================================================================

View File

@ -803,4 +803,7 @@ main:
# CHECK: i64x2.laneselect # encoding: [0xfd,0xd3,0x01]
i64x2.laneselect
# CHECK: i8x16.relaxed_swizzle # encoding: [0xfd,0xa2,0x01]
i8x16.relaxed_swizzle
end_function