diff --git a/include/llvm/IR/IntrinsicsWebAssembly.td b/include/llvm/IR/IntrinsicsWebAssembly.td index bc93137af5f..4ce74d84a72 100644 --- a/include/llvm/IR/IntrinsicsWebAssembly.td +++ b/include/llvm/IR/IntrinsicsWebAssembly.td @@ -172,11 +172,6 @@ def int_wasm_pmax : [LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]>; -// TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged -// to the proposal. -def int_wasm_popcnt : - Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>; - def int_wasm_extmul_low_signed : Intrinsic<[llvm_anyvector_ty], [LLVMSubdivide2VectorType<0>, LLVMSubdivide2VectorType<0>], diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 32f8b5df25c..1cff336cb3e 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -212,6 +212,9 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering( for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32}) setOperationAction(Op, T, Legal); + // And we have popcnt for i8x16 + setOperationAction(ISD::CTPOP, MVT::v16i8, Legal); + // Expand float operations supported for scalars but not SIMD for (auto Op : {ISD::FCOPYSIGN, ISD::FLOG, ISD::FLOG2, ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FRINT}) diff --git a/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td b/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td index ff7c7deed23..bf05b822374 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -833,7 +833,7 @@ defm ABS : SIMDUnaryInt; defm NEG : SIMDUnaryInt; // Population count: popcnt -defm POPCNT : SIMDUnary; +defm POPCNT : SIMDUnary; // Any lane true: any_true defm ANYTRUE : SIMD_I<(outs I32:$dst), (ins V128:$vec), (outs), (ins), [], diff --git a/test/CodeGen/WebAssembly/simd-intrinsics.ll b/test/CodeGen/WebAssembly/simd-intrinsics.ll index d1e141999f4..de9397d791b 100644 --- a/test/CodeGen/WebAssembly/simd-intrinsics.ll +++ b/test/CodeGen/WebAssembly/simd-intrinsics.ll @@ -78,9 +78,9 @@ define <16 x i8> @avgr_u_v16i8(<16 x i8> %x, <16 x i8> %y) { ; CHECK-NEXT: .functype popcnt_v16i8 (v128) -> (v128){{$}} ; CHECK-NEXT: i8x16.popcnt $push[[R:[0-9]+]]=, $0{{$}} ; CHECK-NEXT: return $pop[[R]]{{$}} -declare <16 x i8> @llvm.wasm.popcnt(<16 x i8>) +declare <16 x i8> @llvm.ctpop.v16i8(<16 x i8>) define <16 x i8> @popcnt_v16i8(<16 x i8> %x) { - %a = call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x) + %a = call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %x) ret <16 x i8> %a } diff --git a/test/CodeGen/WebAssembly/simd-unsupported.ll b/test/CodeGen/WebAssembly/simd-unsupported.ll index 67be6a9c6a5..86f621b8c90 100644 --- a/test/CodeGen/WebAssembly/simd-unsupported.ll +++ b/test/CodeGen/WebAssembly/simd-unsupported.ll @@ -10,7 +10,7 @@ target triple = "wasm32-unknown-unknown" ; ============================================================================== ; CHECK-LABEL: ctlz_v16i8: -; CHECK: i32.clz +; CHECK: i8x16.popcnt declare <16 x i8> @llvm.ctlz.v16i8(<16 x i8>, i1) define <16 x i8> @ctlz_v16i8(<16 x i8> %x) { %v = call <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %x, i1 false) @@ -18,14 +18,14 @@ define <16 x i8> @ctlz_v16i8(<16 x i8> %x) { } ; CHECK-LABEL: ctlz_v16i8_undef: -; CHECK: i32.clz +; CHECK: i8x16.popcnt define <16 x i8> @ctlz_v16i8_undef(<16 x i8> %x) { %v = call <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %x, i1 true) ret <16 x i8> %v } ; CHECK-LABEL: cttz_v16i8: -; CHECK: i32.ctz +; CHECK: i8x16.popcnt declare <16 x i8> @llvm.cttz.v16i8(<16 x i8>, i1) define <16 x i8> @cttz_v16i8(<16 x i8> %x) { %v = call <16 x i8> @llvm.cttz.v16i8(<16 x i8> %x, i1 false) @@ -33,21 +33,12 @@ define <16 x i8> @cttz_v16i8(<16 x i8> %x) { } ; CHECK-LABEL: cttz_v16i8_undef: -; CHECK: i32.ctz +; CHECK: i8x16.popcnt define <16 x i8> @cttz_v16i8_undef(<16 x i8> %x) { %v = call <16 x i8> @llvm.cttz.v16i8(<16 x i8> %x, i1 true) ret <16 x i8> %v } -; CHECK-LABEL: ctpop_v16i8: -; Note: expansion does not use i32.popcnt -; CHECK: v128.and -declare <16 x i8> @llvm.ctpop.v16i8(<16 x i8>) -define <16 x i8> @ctpop_v16i8(<16 x i8> %x) { - %v = call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %x) - ret <16 x i8> %v -} - ; CHECK-LABEL: sdiv_v16i8: ; CHECK: i32.div_s define <16 x i8> @sdiv_v16i8(<16 x i8> %x, <16 x i8> %y) {