diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6169,8 +6169,10 @@ return new ICmpInst(ICmpInst::ICMP_SLT, Op0, Zero); } - // For i32: x x >s -1 -> true if sign bit clear - if (Pred == ICmpInst::ICMP_ULT && C->isMinSignedValue()) { + // For i32: x x >s -1 -> true if sign bit clear, + // and exclude a case that can be matched by other patterns. + if (Pred == ICmpInst::ICMP_ULT && C->isMinSignedValue() && + !match(Op0, m_LShr(m_SpecificInt(*C), m_Value()))) { Constant *AllOnes = Constant::getAllOnesValue(Op0->getType()); return new ICmpInst(ICmpInst::ICMP_SGT, Op0, AllOnes); } diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/llvm/test/Transforms/InstCombine/icmp-shr.ll --- a/llvm/test/Transforms/InstCombine/icmp-shr.ll +++ b/llvm/test/Transforms/InstCombine/icmp-shr.ll @@ -1146,12 +1146,9 @@ ret i1 %r } -; TODO: This should reduce to X != 0. - define i1 @lshr_pow2_ult_smin(i8 %x) { ; CHECK-LABEL: @lshr_pow2_ult_smin( -; CHECK-NEXT: [[S:%.*]] = lshr i8 -128, [[X:%.*]] -; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[S]], -1 +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[X:%.*]], 0 ; CHECK-NEXT: ret i1 [[R]] ; %s = lshr i8 128, %x