From d2fab30827dd195c50bd1a92be6bf530280bbcde Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 22 Feb 2018 23:46:28 +0000 Subject: [PATCH] [X86] Turn setne X, signedmin into setgt X, signedmin in LowerVSETCC to avoid an invert This will fix one of the regressions from D42948. Differential Revision: https://reviews.llvm.org/D43531 llvm-svn: 325840 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 9 +++++++++ llvm/test/CodeGen/X86/vector-compare-simplify.ll | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index ba95620..5dd0b9e 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -18099,6 +18099,15 @@ static SDValue LowerVSETCC(SDValue Op, const X86Subtarget &Subtarget, } } + // If this is a SETNE against the signed minimum value, change it to SETGT. + // Otherwise we use PCMPEQ+invert. + APInt ConstValue; + if (Cond == ISD::SETNE && + ISD::isConstantSplatVector(Op1.getNode(), ConstValue), + ConstValue.isMinSignedValue()) { + Cond = ISD::SETGT; + } + // If both operands are known non-negative, then an unsigned compare is the // same as a signed compare and there's no need to flip signbits. // TODO: We could check for more general simplifications here since we're diff --git a/llvm/test/CodeGen/X86/vector-compare-simplify.ll b/llvm/test/CodeGen/X86/vector-compare-simplify.ll index 718e69b..f1ac601 100644 --- a/llvm/test/CodeGen/X86/vector-compare-simplify.ll +++ b/llvm/test/CodeGen/X86/vector-compare-simplify.ll @@ -334,3 +334,14 @@ define <4 x i32> @uge_smin(<4 x i32> %x) { ret <4 x i32> %r } +; Make sure we can efficiently handle ne smin by turning into sgt. +define <4 x i32> @ne_smin(<4 x i32> %x) { +; CHECK-LABEL: ne_smin: +; CHECK: # %bb.0: +; CHECK-NEXT: pcmpgtd {{.*}}(%rip), %xmm0 +; CHECK-NEXT: retq + %cmp = icmp ne <4 x i32> %x, + %r = sext <4 x i1> %cmp to <4 x i32> + ret <4 x i32> %r +} + -- 2.7.4