From d982f1e0c69f3447c4520ae4c010520f62ed1174 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Sat, 30 Jul 2022 01:43:25 +0000 Subject: [PATCH] [InstCombine] Refactor foldICmpMulConstant This is a follow-up to 2ebfda2417 (replace "if" with "else if" since the cases nuw/nsw were meant to be handled separately). Test plan: 1/ ninja check-llvm check-clang check-lld 2/ Bootstrapped LLVM/Clang pass tests --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 4 +--- llvm/test/Transforms/InstCombine/icmp-mul.ll | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index b61567a77323..fc3b115e09bd 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2053,9 +2053,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 e07e2d05136a..65a7fccc8872 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