diff --git a/llvm/lib/CodeGen/ExpandVectorPredication.cpp b/llvm/lib/CodeGen/ExpandVectorPredication.cpp --- a/llvm/lib/CodeGen/ExpandVectorPredication.cpp +++ b/llvm/lib/CodeGen/ExpandVectorPredication.cpp @@ -171,6 +171,10 @@ Value *expandPredicationInBinaryOperator(IRBuilder<> &Builder, VPIntrinsic &PI); + /// Lower this VP int call to a unpredicated int call. + Value *expandPredicationToIntCall(IRBuilder<> &Builder, VPIntrinsic &PI, + unsigned UnpredicatedIntrinsicID); + /// Lower this VP fp call to a unpredicated fp call. Value *expandPredicationToFPCall(IRBuilder<> &Builder, VPIntrinsic &PI, unsigned UnpredicatedIntrinsicID); @@ -279,6 +283,26 @@ return NewBinOp; } +Value *CachingVPExpander::expandPredicationToIntCall( + IRBuilder<> &Builder, VPIntrinsic &VPI, unsigned UnpredicatedIntrinsicID) { + switch (UnpredicatedIntrinsicID) { + case Intrinsic::abs: + case Intrinsic::smax: + case Intrinsic::smin: + case Intrinsic::umax: + case Intrinsic::umin: { + Value *Op0 = VPI.getOperand(0); + Value *Op1 = VPI.getOperand(1); + Function *Fn = Intrinsic::getDeclaration( + VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); + Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName()); + replaceOperation(*NewOp, VPI); + return NewOp; + } + } + return nullptr; +} + Value *CachingVPExpander::expandPredicationToFPCall( IRBuilder<> &Builder, VPIntrinsic &VPI, unsigned UnpredicatedIntrinsicID) { assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) && @@ -635,6 +659,16 @@ replaceOperation(*NewNegOp, VPI); return NewNegOp; } + case Intrinsic::vp_abs: + return expandPredicationToIntCall(Builder, VPI, Intrinsic::abs); + case Intrinsic::vp_smax: + return expandPredicationToIntCall(Builder, VPI, Intrinsic::smax); + case Intrinsic::vp_smin: + return expandPredicationToIntCall(Builder, VPI, Intrinsic::smin); + case Intrinsic::vp_umax: + return expandPredicationToIntCall(Builder, VPI, Intrinsic::umax); + case Intrinsic::vp_umin: + return expandPredicationToIntCall(Builder, VPI, Intrinsic::umin); case Intrinsic::vp_fabs: return expandPredicationToFPCall(Builder, VPI, Intrinsic::fabs); case Intrinsic::vp_sqrt: diff --git a/llvm/test/CodeGen/X86/expand-vp-int-intrinsics.ll b/llvm/test/CodeGen/X86/expand-vp-int-intrinsics.ll --- a/llvm/test/CodeGen/X86/expand-vp-int-intrinsics.ll +++ b/llvm/test/CodeGen/X86/expand-vp-int-intrinsics.ll @@ -1,10 +1,18 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=X86 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefixes=SSE ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=AVX,AVX1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX,AVX2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512vl | FileCheck %s --check-prefixes=AVX,AVX512 define void @vp_add_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_add_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpaddd %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_add_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: paddd %xmm1, %xmm0 @@ -23,6 +31,13 @@ declare <4 x i32> @llvm.vp.add.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_sub_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_sub_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpsubd %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_sub_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: psubd %xmm1, %xmm0 @@ -41,6 +56,13 @@ declare <4 x i32> @llvm.vp.sub.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_mul_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_mul_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpmulld %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_mul_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3] @@ -65,6 +87,42 @@ declare <4 x i32> @llvm.vp.mul.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_sdiv_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_sdiv_v4i32: +; X86: # %bb.0: +; X86-NEXT: pushl %edi +; X86-NEXT: pushl %esi +; X86-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %xmm2 +; X86-NEXT: vmovdqa {{.*#+}} xmm3 = [0,1,2,3] +; X86-NEXT: vpmaxud %xmm3, %xmm2, %xmm2 +; X86-NEXT: vpcmpeqd %xmm3, %xmm2, %xmm2 +; X86-NEXT: vblendvps %xmm2, {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1, %xmm1 +; X86-NEXT: vextractps $1, %xmm1, %ecx +; X86-NEXT: vpextrd $1, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: movl %eax, %ecx +; X86-NEXT: vmovd %xmm1, %edi +; X86-NEXT: vmovd %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %edi +; X86-NEXT: vmovd %eax, %xmm2 +; X86-NEXT: vpinsrd $1, %ecx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $2, %xmm1, %ecx +; X86-NEXT: vpextrd $2, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: vpinsrd $2, %eax, %xmm2, %xmm2 +; X86-NEXT: vpextrd $3, %xmm1, %ecx +; X86-NEXT: vpextrd $3, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: vpinsrd $3, %eax, %xmm2, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%esi) +; X86-NEXT: popl %esi +; X86-NEXT: popl %edi +; X86-NEXT: retl +; ; SSE-LABEL: vp_sdiv_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: movd %esi, %xmm2 @@ -208,6 +266,42 @@ declare <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_udiv_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_udiv_v4i32: +; X86: # %bb.0: +; X86-NEXT: pushl %edi +; X86-NEXT: pushl %esi +; X86-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %xmm2 +; X86-NEXT: vmovdqa {{.*#+}} xmm3 = [0,1,2,3] +; X86-NEXT: vpmaxud %xmm3, %xmm2, %xmm2 +; X86-NEXT: vpcmpeqd %xmm3, %xmm2, %xmm2 +; X86-NEXT: vblendvps %xmm2, {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1, %xmm1 +; X86-NEXT: vextractps $1, %xmm1, %ecx +; X86-NEXT: vpextrd $1, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: movl %eax, %ecx +; X86-NEXT: vmovd %xmm1, %edi +; X86-NEXT: vmovd %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %edi +; X86-NEXT: vmovd %eax, %xmm2 +; X86-NEXT: vpinsrd $1, %ecx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $2, %xmm1, %ecx +; X86-NEXT: vpextrd $2, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: vpinsrd $2, %eax, %xmm2, %xmm2 +; X86-NEXT: vpextrd $3, %xmm1, %ecx +; X86-NEXT: vpextrd $3, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: vpinsrd $3, %eax, %xmm2, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%esi) +; X86-NEXT: popl %esi +; X86-NEXT: popl %edi +; X86-NEXT: retl +; ; SSE-LABEL: vp_udiv_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: movd %esi, %xmm2 @@ -351,6 +445,42 @@ declare <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_srem_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_srem_v4i32: +; X86: # %bb.0: +; X86-NEXT: pushl %edi +; X86-NEXT: pushl %esi +; X86-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %xmm2 +; X86-NEXT: vmovdqa {{.*#+}} xmm3 = [0,1,2,3] +; X86-NEXT: vpmaxud %xmm3, %xmm2, %xmm2 +; X86-NEXT: vpcmpeqd %xmm3, %xmm2, %xmm2 +; X86-NEXT: vblendvps %xmm2, {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1, %xmm1 +; X86-NEXT: vextractps $1, %xmm1, %ecx +; X86-NEXT: vpextrd $1, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: movl %edx, %ecx +; X86-NEXT: vmovd %xmm1, %edi +; X86-NEXT: vmovd %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %edi +; X86-NEXT: vmovd %edx, %xmm2 +; X86-NEXT: vpinsrd $1, %ecx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $2, %xmm1, %ecx +; X86-NEXT: vpextrd $2, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: vpinsrd $2, %edx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $3, %xmm1, %ecx +; X86-NEXT: vpextrd $3, %xmm0, %eax +; X86-NEXT: cltd +; X86-NEXT: idivl %ecx +; X86-NEXT: vpinsrd $3, %edx, %xmm2, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%esi) +; X86-NEXT: popl %esi +; X86-NEXT: popl %edi +; X86-NEXT: retl +; ; SSE-LABEL: vp_srem_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: movd %esi, %xmm2 @@ -494,6 +624,42 @@ declare <4 x i32> @llvm.vp.srem.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_urem_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_urem_v4i32: +; X86: # %bb.0: +; X86-NEXT: pushl %edi +; X86-NEXT: pushl %esi +; X86-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %xmm2 +; X86-NEXT: vmovdqa {{.*#+}} xmm3 = [0,1,2,3] +; X86-NEXT: vpmaxud %xmm3, %xmm2, %xmm2 +; X86-NEXT: vpcmpeqd %xmm3, %xmm2, %xmm2 +; X86-NEXT: vblendvps %xmm2, {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1, %xmm1 +; X86-NEXT: vextractps $1, %xmm1, %ecx +; X86-NEXT: vpextrd $1, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: movl %edx, %ecx +; X86-NEXT: vmovd %xmm1, %edi +; X86-NEXT: vmovd %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %edi +; X86-NEXT: vmovd %edx, %xmm2 +; X86-NEXT: vpinsrd $1, %ecx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $2, %xmm1, %ecx +; X86-NEXT: vpextrd $2, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: vpinsrd $2, %edx, %xmm2, %xmm2 +; X86-NEXT: vpextrd $3, %xmm1, %ecx +; X86-NEXT: vpextrd $3, %xmm0, %eax +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: divl %ecx +; X86-NEXT: vpinsrd $3, %edx, %xmm2, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%esi) +; X86-NEXT: popl %esi +; X86-NEXT: popl %edi +; X86-NEXT: retl +; ; SSE-LABEL: vp_urem_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: movd %esi, %xmm2 @@ -637,6 +803,24 @@ declare <4 x i32> @llvm.vp.urem.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_ashr_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_ashr_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpsrldq {{.*#+}} xmm2 = xmm1[12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero +; X86-NEXT: vpsrad %xmm2, %xmm0, %xmm2 +; X86-NEXT: vpsrlq $32, %xmm1, %xmm3 +; X86-NEXT: vpsrad %xmm3, %xmm0, %xmm3 +; X86-NEXT: vpblendw {{.*#+}} xmm2 = xmm3[0,1,2,3],xmm2[4,5,6,7] +; X86-NEXT: vpxor %xmm3, %xmm3, %xmm3 +; X86-NEXT: vpunpckhdq {{.*#+}} xmm3 = xmm1[2],xmm3[2],xmm1[3],xmm3[3] +; X86-NEXT: vpsrad %xmm3, %xmm0, %xmm3 +; X86-NEXT: vpmovzxdq {{.*#+}} xmm1 = xmm1[0],zero,xmm1[1],zero +; X86-NEXT: vpsrad %xmm1, %xmm0, %xmm0 +; X86-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1,2,3],xmm3[4,5,6,7] +; X86-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,3],xmm0[4,5],xmm2[6,7] +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_ashr_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: pshuflw {{.*#+}} xmm2 = xmm1[2,3,3,3,4,5,6,7] @@ -692,6 +876,24 @@ declare <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_lshr_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_lshr_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpsrldq {{.*#+}} xmm2 = xmm1[12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero +; X86-NEXT: vpsrld %xmm2, %xmm0, %xmm2 +; X86-NEXT: vpsrlq $32, %xmm1, %xmm3 +; X86-NEXT: vpsrld %xmm3, %xmm0, %xmm3 +; X86-NEXT: vpblendw {{.*#+}} xmm2 = xmm3[0,1,2,3],xmm2[4,5,6,7] +; X86-NEXT: vpxor %xmm3, %xmm3, %xmm3 +; X86-NEXT: vpunpckhdq {{.*#+}} xmm3 = xmm1[2],xmm3[2],xmm1[3],xmm3[3] +; X86-NEXT: vpsrld %xmm3, %xmm0, %xmm3 +; X86-NEXT: vpmovzxdq {{.*#+}} xmm1 = xmm1[0],zero,xmm1[1],zero +; X86-NEXT: vpsrld %xmm1, %xmm0, %xmm0 +; X86-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1,2,3],xmm3[4,5,6,7] +; X86-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,3],xmm0[4,5],xmm2[6,7] +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_lshr_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: pshuflw {{.*#+}} xmm2 = xmm1[2,3,3,3,4,5,6,7] @@ -747,6 +949,16 @@ declare <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_shl_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_shl_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpslld $23, %xmm1, %xmm1 +; X86-NEXT: vpaddd {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1, %xmm1 +; X86-NEXT: vcvttps2dq %xmm1, %xmm1 +; X86-NEXT: vpmulld %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_shl_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: pslld $23, %xmm1 @@ -789,6 +1001,13 @@ declare <4 x i32> @llvm.vp.shl.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_or_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_or_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vorps %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovaps %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_or_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: orps %xmm1, %xmm0 @@ -807,6 +1026,13 @@ declare <4 x i32> @llvm.vp.or.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_and_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_and_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vorps %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovaps %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_and_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: orps %xmm1, %xmm0 @@ -825,6 +1051,13 @@ declare <4 x i32> @llvm.vp.and.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) define void @vp_xor_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_xor_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vxorps %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovaps %xmm0, (%eax) +; X86-NEXT: retl +; ; SSE-LABEL: vp_xor_v4i32: ; SSE: # %bb.0: ; SSE-NEXT: xorps %xmm1, %xmm0 @@ -842,42 +1075,152 @@ } declare <4 x i32> @llvm.vp.xor.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) -; TODO: llvm.vp.abs.v4i32 -;define void @vp_abs_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { -; %res = call <4 x i32> @llvm.vp.abs.v4i32(<4 x i32> %a0, <4 x i1> , i32 %vp) -; store <4 x i32> %res, ptr %out -; ret void -;} -;declare <4 x i32> @llvm.vp.abs.v4i32(<4 x i32>, <4 x i1>, i32) +define void @vp_abs_v4i32(<4 x i32> %a0, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_abs_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpabsd %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; +; SSE-LABEL: vp_abs_v4i32: +; SSE: # %bb.0: +; SSE-NEXT: movdqa %xmm0, %xmm1 +; SSE-NEXT: psrad $31, %xmm1 +; SSE-NEXT: pxor %xmm1, %xmm0 +; SSE-NEXT: psubd %xmm1, %xmm0 +; SSE-NEXT: movdqa %xmm0, (%rdi) +; SSE-NEXT: retq +; +; AVX-LABEL: vp_abs_v4i32: +; AVX: # %bb.0: +; AVX-NEXT: vpabsd %xmm0, %xmm0 +; AVX-NEXT: vmovdqa %xmm0, (%rdi) +; AVX-NEXT: retq + %res = call <4 x i32> @llvm.vp.abs.v4i32(<4 x i32> %a0, i1 false, <4 x i1> , i32 %vp) + store <4 x i32> %res, ptr %out + ret void +} +declare <4 x i32> @llvm.vp.abs.v4i32(<4 x i32>, i1 immarg, <4 x i1>, i32) -; TODO: llvm.vp.smax.v4i32 -;define void @vp_smax_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { -; %res = call <4 x i32> @llvm.vp.smax.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) -; store <4 x i32> %res, ptr %out -; ret void -;} -;declare <4 x i32> @llvm.vp.smax.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) +define void @vp_smax_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_smax_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; +; SSE-LABEL: vp_smax_v4i32: +; SSE: # %bb.0: +; SSE-NEXT: movdqa %xmm0, %xmm2 +; SSE-NEXT: pcmpgtd %xmm1, %xmm2 +; SSE-NEXT: pand %xmm2, %xmm0 +; SSE-NEXT: pandn %xmm1, %xmm2 +; SSE-NEXT: por %xmm0, %xmm2 +; SSE-NEXT: movdqa %xmm2, (%rdi) +; SSE-NEXT: retq +; +; AVX-LABEL: vp_smax_v4i32: +; AVX: # %bb.0: +; AVX-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0 +; AVX-NEXT: vmovdqa %xmm0, (%rdi) +; AVX-NEXT: retq + %res = call <4 x i32> @llvm.vp.smax.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) + store <4 x i32> %res, ptr %out + ret void +} +declare <4 x i32> @llvm.vp.smax.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) -; TODO: llvm.vp.smin.v4i32 -;define void @vp_smin_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { -; %res = call <4 x i32> @llvm.vp.smin.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) -; store <4 x i32> %res, ptr %out -; ret void -;} -;declare <4 x i32> @llvm.vp.smin.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) +define void @vp_smin_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_smin_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpminsd %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; +; SSE-LABEL: vp_smin_v4i32: +; SSE: # %bb.0: +; SSE-NEXT: movdqa %xmm1, %xmm2 +; SSE-NEXT: pcmpgtd %xmm0, %xmm2 +; SSE-NEXT: pand %xmm2, %xmm0 +; SSE-NEXT: pandn %xmm1, %xmm2 +; SSE-NEXT: por %xmm0, %xmm2 +; SSE-NEXT: movdqa %xmm2, (%rdi) +; SSE-NEXT: retq +; +; AVX-LABEL: vp_smin_v4i32: +; AVX: # %bb.0: +; AVX-NEXT: vpminsd %xmm1, %xmm0, %xmm0 +; AVX-NEXT: vmovdqa %xmm0, (%rdi) +; AVX-NEXT: retq + %res = call <4 x i32> @llvm.vp.smin.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) + store <4 x i32> %res, ptr %out + ret void +} +declare <4 x i32> @llvm.vp.smin.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) -; TODO: llvm.vp.umax.v4i32 -;define void @vp_umax_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { -; %res = call <4 x i32> @llvm.vp.umax.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) -; store <4 x i32> %res, ptr %out -; ret void -;} -;declare <4 x i32> @llvm.vp.umax.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) +define void @vp_umax_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_umax_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpmaxud %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; +; SSE-LABEL: vp_umax_v4i32: +; SSE: # %bb.0: +; SSE-NEXT: movdqa {{.*#+}} xmm2 = [2147483648,2147483648,2147483648,2147483648] +; SSE-NEXT: movdqa %xmm1, %xmm3 +; SSE-NEXT: pxor %xmm2, %xmm3 +; SSE-NEXT: pxor %xmm0, %xmm2 +; SSE-NEXT: pcmpgtd %xmm3, %xmm2 +; SSE-NEXT: pand %xmm2, %xmm0 +; SSE-NEXT: pandn %xmm1, %xmm2 +; SSE-NEXT: por %xmm0, %xmm2 +; SSE-NEXT: movdqa %xmm2, (%rdi) +; SSE-NEXT: retq +; +; AVX-LABEL: vp_umax_v4i32: +; AVX: # %bb.0: +; AVX-NEXT: vpmaxud %xmm1, %xmm0, %xmm0 +; AVX-NEXT: vmovdqa %xmm0, (%rdi) +; AVX-NEXT: retq + %res = call <4 x i32> @llvm.vp.umax.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) + store <4 x i32> %res, ptr %out + ret void +} +declare <4 x i32> @llvm.vp.umax.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) -; TODO: llvm.vp.umin.v4i32 -;define void @vp_umin_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { -; %res = call <4 x i32> @llvm.vp.umin.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) -; store <4 x i32> %res, ptr %out -; ret void -;} -;declare <4 x i32> @llvm.vp.umin.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32) +define void @vp_umin_v4i32(<4 x i32> %a0, <4 x i32> %a1, ptr %out, i32 %vp) nounwind { +; X86-LABEL: vp_umin_v4i32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: vpminud %xmm1, %xmm0, %xmm0 +; X86-NEXT: vmovdqa %xmm0, (%eax) +; X86-NEXT: retl +; +; SSE-LABEL: vp_umin_v4i32: +; SSE: # %bb.0: +; SSE-NEXT: movdqa {{.*#+}} xmm2 = [2147483648,2147483648,2147483648,2147483648] +; SSE-NEXT: movdqa %xmm0, %xmm3 +; SSE-NEXT: pxor %xmm2, %xmm3 +; SSE-NEXT: pxor %xmm1, %xmm2 +; SSE-NEXT: pcmpgtd %xmm3, %xmm2 +; SSE-NEXT: pand %xmm2, %xmm0 +; SSE-NEXT: pandn %xmm1, %xmm2 +; SSE-NEXT: por %xmm0, %xmm2 +; SSE-NEXT: movdqa %xmm2, (%rdi) +; SSE-NEXT: retq +; +; AVX-LABEL: vp_umin_v4i32: +; AVX: # %bb.0: +; AVX-NEXT: vpminud %xmm1, %xmm0, %xmm0 +; AVX-NEXT: vmovdqa %xmm0, (%rdi) +; AVX-NEXT: retq + %res = call <4 x i32> @llvm.vp.umin.v4i32(<4 x i32> %a0, <4 x i32> %a1, <4 x i1> , i32 %vp) + store <4 x i32> %res, ptr %out + ret void +} +declare <4 x i32> @llvm.vp.umin.v4i32(<4 x i32>, <4 x i32>, <4 x i1>, i32)