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 @@ -2061,15 +2061,12 @@ } } - if (!Mul->hasNoSignedWrap() && !Mul->hasNoUnsignedWrap()) - return nullptr; - // With a matching no-overflow guarantee, fold the constants: // (X * MulC) < C --> X < (C / MulC) // (X * MulC) > C --> X > (C / MulC) // TODO: Assert that Pred is not equal to SGE, SLE, UGE, ULE? Constant *NewC = nullptr; - if (Mul->hasNoSignedWrap()) { + if (Mul->hasNoSignedWrap() && ICmpInst::isSigned(Pred)) { // MININT / -1 --> overflow. if (C.isMinSignedValue() && MulC->isAllOnes()) return nullptr; @@ -2082,8 +2079,7 @@ if (Pred == ICmpInst::ICMP_SLE || Pred == ICmpInst::ICMP_SGT) NewC = ConstantInt::get( MulTy, APIntOps::RoundingSDiv(C, *MulC, APInt::Rounding::DOWN)); - } else { - assert(Mul->hasNoUnsignedWrap() && "Expected mul nuw"); + } else if (Mul->hasNoUnsignedWrap()) { if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE) NewC = ConstantInt::get( MulTy, APIntOps::RoundingUDiv(C, *MulC, APInt::Rounding::UP)); diff --git a/llvm/test/Transforms/InstCombine/icmp-mul.ll b/llvm/test/Transforms/InstCombine/icmp-mul.ll --- a/llvm/test/Transforms/InstCombine/icmp-mul.ll +++ b/llvm/test/Transforms/InstCombine/icmp-mul.ll @@ -946,9 +946,7 @@ define i1 @splat_mul_unknown_lz(i32 %x) { ; CHECK-LABEL: @splat_mul_unknown_lz( -; CHECK-NEXT: [[Z:%.*]] = zext i32 [[X:%.*]] to i128 -; CHECK-NEXT: [[M:%.*]] = mul nuw nsw i128 [[Z]], 18446744078004518913 -; CHECK-NEXT: [[R:%.*]] = icmp ult i128 [[M]], 39614081257132168796771975168 +; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: ret i1 [[R]] ; %z = zext i32 %x to i128