Index: llvm/lib/Target/X86/X86ISelLowering.cpp =================================================================== --- llvm/lib/Target/X86/X86ISelLowering.cpp +++ llvm/lib/Target/X86/X86ISelLowering.cpp @@ -23078,10 +23078,11 @@ return splitIntVSETCC(VT, Op0, Op1, Cond, DAG, dl); } - // If this is a SETNE against the signed minimum value, change it to SETGT. - // If this is a SETNE against the signed maximum value, change it to SETLT. - // which will be swapped to SETGT. - // Otherwise we use PCMPEQ+invert. + // If we have a limit constant, try to form PCMPGT (signed cmp) to avoid + // not-of-PCMPEQ: + // X != INT_MIN --> X >s INT_MIN + // X != INT_MAX --> X INT_MAX >s X + // +X != 0 --> +X >s 0 APInt ConstValue; if (Cond == ISD::SETNE && ISD::isConstantSplatVector(Op1.getNode(), ConstValue)) { @@ -23089,6 +23090,8 @@ Cond = ISD::SETGT; else if (ConstValue.isMaxSignedValue()) Cond = ISD::SETLT; + else if (ConstValue.isNullValue() && DAG.SignBitIsZero(Op0)) + Cond = ISD::SETGT; } // If both operands are known non-negative, then an unsigned compare is the Index: llvm/test/CodeGen/X86/setcc-lowering.ll =================================================================== --- llvm/test/CodeGen/X86/setcc-lowering.ll +++ llvm/test/CodeGen/X86/setcc-lowering.ll @@ -109,18 +109,14 @@ ; AVX: # %bb.0: ; AVX-NEXT: vpmovzxbd {{.*#+}} xmm0 = xmm0[0],zero,zero,zero,xmm0[1],zero,zero,zero,xmm0[2],zero,zero,zero,xmm0[3],zero,zero,zero ; AVX-NEXT: vpxor %xmm1, %xmm1, %xmm1 -; AVX-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0 -; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1 -; AVX-NEXT: vpxor %xmm1, %xmm0, %xmm0 +; AVX-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0 ; AVX-NEXT: retq ; ; KNL-32-LABEL: pcmpgt: ; KNL-32: # %bb.0: ; KNL-32-NEXT: vpmovzxbd {{.*#+}} xmm0 = xmm0[0],zero,zero,zero,xmm0[1],zero,zero,zero,xmm0[2],zero,zero,zero,xmm0[3],zero,zero,zero ; KNL-32-NEXT: vpxor %xmm1, %xmm1, %xmm1 -; KNL-32-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0 -; KNL-32-NEXT: vpternlogq $15, %zmm0, %zmm0, %zmm0 -; KNL-32-NEXT: # kill: def $xmm0 killed $xmm0 killed $zmm0 +; KNL-32-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0 ; KNL-32-NEXT: retl %zext = zext <4 x i8> %x to <4 x i32> %icmp = icmp ne <4 x i32> %zext, zeroinitializer Index: llvm/test/CodeGen/X86/vec_umulo.ll =================================================================== --- llvm/test/CodeGen/X86/vec_umulo.ll +++ llvm/test/CodeGen/X86/vec_umulo.ll @@ -2666,14 +2666,13 @@ ; SSE2-NEXT: pxor %xmm4, %xmm4 ; SSE2-NEXT: pcmpeqd %xmm4, %xmm3 ; SSE2-NEXT: pcmpeqd %xmm5, %xmm5 -; SSE2-NEXT: pxor %xmm5, %xmm3 +; SSE2-NEXT: pxor %xmm3, %xmm5 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm2[0,2,2,3] -; SSE2-NEXT: pshufd {{.*#+}} xmm6 = xmm1[0,2,2,3] -; SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm6[0],xmm0[1],xmm6[1] +; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm1[0,2,2,3] +; SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1] ; SSE2-NEXT: psrld $24, %xmm0 -; SSE2-NEXT: pcmpeqd %xmm4, %xmm0 -; SSE2-NEXT: pxor %xmm5, %xmm0 -; SSE2-NEXT: por %xmm3, %xmm0 +; SSE2-NEXT: pcmpgtd %xmm4, %xmm0 +; SSE2-NEXT: por %xmm5, %xmm0 ; SSE2-NEXT: movd %xmm2, %eax ; SSE2-NEXT: movw %ax, (%rdi) ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm2[2,3,2,3] @@ -2710,14 +2709,13 @@ ; SSSE3-NEXT: pxor %xmm4, %xmm4 ; SSSE3-NEXT: pcmpeqd %xmm4, %xmm3 ; SSSE3-NEXT: pcmpeqd %xmm5, %xmm5 -; SSSE3-NEXT: pxor %xmm5, %xmm3 +; SSSE3-NEXT: pxor %xmm3, %xmm5 ; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm2[0,2,2,3] -; SSSE3-NEXT: pshufd {{.*#+}} xmm6 = xmm1[0,2,2,3] -; SSSE3-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm6[0],xmm0[1],xmm6[1] +; SSSE3-NEXT: pshufd {{.*#+}} xmm3 = xmm1[0,2,2,3] +; SSSE3-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1] ; SSSE3-NEXT: psrld $24, %xmm0 -; SSSE3-NEXT: pcmpeqd %xmm4, %xmm0 -; SSSE3-NEXT: pxor %xmm5, %xmm0 -; SSSE3-NEXT: por %xmm3, %xmm0 +; SSSE3-NEXT: pcmpgtd %xmm4, %xmm0 +; SSSE3-NEXT: por %xmm5, %xmm0 ; SSSE3-NEXT: movd %xmm2, %eax ; SSSE3-NEXT: movw %ax, (%rdi) ; SSSE3-NEXT: pshufd {{.*#+}} xmm2 = xmm2[2,3,2,3] @@ -2751,19 +2749,18 @@ ; SSE41-NEXT: pmuludq %xmm1, %xmm0 ; SSE41-NEXT: pshufd {{.*#+}} xmm4 = xmm0[1,1,3,3] ; SSE41-NEXT: pblendw {{.*#+}} xmm4 = xmm4[0,1],xmm3[2,3],xmm4[4,5],xmm3[6,7] -; SSE41-NEXT: pxor %xmm0, %xmm0 -; SSE41-NEXT: pcmpeqd %xmm0, %xmm4 -; SSE41-NEXT: pcmpeqd %xmm3, %xmm3 -; SSE41-NEXT: pxor %xmm3, %xmm4 +; SSE41-NEXT: pxor %xmm3, %xmm3 +; SSE41-NEXT: pcmpeqd %xmm3, %xmm4 +; SSE41-NEXT: pcmpeqd %xmm0, %xmm0 +; SSE41-NEXT: pxor %xmm4, %xmm0 ; SSE41-NEXT: pmulld %xmm2, %xmm1 ; SSE41-NEXT: pextrd $3, %xmm1, %eax ; SSE41-NEXT: pextrd $2, %xmm1, %ecx ; SSE41-NEXT: pextrd $1, %xmm1, %edx ; SSE41-NEXT: movd %xmm1, %esi ; SSE41-NEXT: psrld $24, %xmm1 -; SSE41-NEXT: pcmpeqd %xmm1, %xmm0 -; SSE41-NEXT: pxor %xmm3, %xmm0 -; SSE41-NEXT: por %xmm4, %xmm0 +; SSE41-NEXT: pcmpgtd %xmm3, %xmm1 +; SSE41-NEXT: por %xmm1, %xmm0 ; SSE41-NEXT: movw %ax, 9(%rdi) ; SSE41-NEXT: movw %cx, 6(%rdi) ; SSE41-NEXT: movw %dx, 3(%rdi) @@ -2795,8 +2792,7 @@ ; AVX1-NEXT: vpxor %xmm4, %xmm2, %xmm2 ; AVX1-NEXT: vpmulld %xmm1, %xmm0, %xmm1 ; AVX1-NEXT: vpsrld $24, %xmm1, %xmm0 -; AVX1-NEXT: vpcmpeqd %xmm3, %xmm0, %xmm0 -; AVX1-NEXT: vpxor %xmm4, %xmm0, %xmm0 +; AVX1-NEXT: vpcmpgtd %xmm3, %xmm0, %xmm0 ; AVX1-NEXT: vpor %xmm2, %xmm0, %xmm0 ; AVX1-NEXT: vpextrd $3, %xmm1, %eax ; AVX1-NEXT: movw %ax, 9(%rdi) @@ -2833,8 +2829,7 @@ ; AVX2-NEXT: vpxor %xmm4, %xmm2, %xmm2 ; AVX2-NEXT: vpmulld %xmm1, %xmm0, %xmm1 ; AVX2-NEXT: vpsrld $24, %xmm1, %xmm0 -; AVX2-NEXT: vpcmpeqd %xmm3, %xmm0, %xmm0 -; AVX2-NEXT: vpxor %xmm4, %xmm0, %xmm0 +; AVX2-NEXT: vpcmpgtd %xmm3, %xmm0, %xmm0 ; AVX2-NEXT: vpor %xmm2, %xmm0, %xmm0 ; AVX2-NEXT: vpextrd $3, %xmm1, %eax ; AVX2-NEXT: movw %ax, 9(%rdi) Index: llvm/test/CodeGen/X86/vsel-cmp-load.ll =================================================================== --- llvm/test/CodeGen/X86/vsel-cmp-load.ll +++ llvm/test/CodeGen/X86/vsel-cmp-load.ll @@ -57,8 +57,8 @@ ; AVX2: # %bb.0: ; AVX2-NEXT: vpmovzxwq {{.*#+}} ymm2 = mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero ; AVX2-NEXT: vpxor %xmm3, %xmm3, %xmm3 -; AVX2-NEXT: vpcmpeqq %ymm3, %ymm2, %ymm2 -; AVX2-NEXT: vblendvpd %ymm2, %ymm1, %ymm0, %ymm0 +; AVX2-NEXT: vpcmpgtq %ymm3, %ymm2, %ymm2 +; AVX2-NEXT: vblendvpd %ymm2, %ymm0, %ymm1, %ymm0 ; AVX2-NEXT: retq ; ; AVX512-LABEL: ne_zero: @@ -189,8 +189,8 @@ ; AVX2: # %bb.0: ; AVX2-NEXT: vpmovzxbd {{.*#+}} ymm2 = mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero,mem[4],zero,zero,zero,mem[5],zero,zero,zero,mem[6],zero,zero,zero,mem[7],zero,zero,zero ; AVX2-NEXT: vpxor %xmm3, %xmm3, %xmm3 -; AVX2-NEXT: vpcmpeqd %ymm3, %ymm2, %ymm2 -; AVX2-NEXT: vblendvps %ymm2, %ymm1, %ymm0, %ymm0 +; AVX2-NEXT: vpcmpgtd %ymm3, %ymm2, %ymm2 +; AVX2-NEXT: vblendvps %ymm2, %ymm0, %ymm1, %ymm0 ; AVX2-NEXT: retq ; ; AVX512-LABEL: ne_zero_fp_select: