diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 158d2e8289e0b..edbd4091d1d2a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2040,9 +2040,7 @@ Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp, NewC = ConstantInt::get( Mul->getType(), APIntOps::RoundingSDiv(C, *MulC, APInt::Rounding::DOWN)); - } - - if (Mul->hasNoUnsignedWrap()) { + } else if (Mul->hasNoUnsignedWrap()) { if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE) NewC = ConstantInt::get( Mul->getType(), diff --git a/llvm/test/Transforms/InstCombine/icmp-mul.ll b/llvm/test/Transforms/InstCombine/icmp-mul.ll index e07e2d05136a1..65a7fccc8872b 100644 --- a/llvm/test/Transforms/InstCombine/icmp-mul.ll +++ b/llvm/test/Transforms/InstCombine/icmp-mul.ll @@ -860,7 +860,9 @@ define i1 @splat_mul_known_lz(i32 %x) { define i1 @splat_mul_unknown_lz(i32 %x) { ; CHECK-LABEL: @splat_mul_unknown_lz( -; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; 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: ret i1 [[R]] ; %z = zext i32 %x to i128