Skip to content

Commit 0777364

Browse files
alexander-shaposhnikovtru
authored andcommitted
[InstCombine] Refactor foldICmpMulConstant
This is a follow-up to 2ebfda2 (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 (cherry picked from commit d982f1e)
1 parent 69c35fa commit 0777364

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,9 +2040,7 @@ Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp,
20402040
NewC = ConstantInt::get(
20412041
Mul->getType(),
20422042
APIntOps::RoundingSDiv(C, *MulC, APInt::Rounding::DOWN));
2043-
}
2044-
2045-
if (Mul->hasNoUnsignedWrap()) {
2043+
} else if (Mul->hasNoUnsignedWrap()) {
20462044
if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE)
20472045
NewC = ConstantInt::get(
20482046
Mul->getType(),

llvm/test/Transforms/InstCombine/icmp-mul.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,9 @@ define i1 @splat_mul_known_lz(i32 %x) {
860860

861861
define i1 @splat_mul_unknown_lz(i32 %x) {
862862
; CHECK-LABEL: @splat_mul_unknown_lz(
863-
; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[X:%.*]], -1
863+
; CHECK-NEXT: [[Z:%.*]] = zext i32 [[X:%.*]] to i128
864+
; CHECK-NEXT: [[M:%.*]] = mul nuw nsw i128 [[Z]], 18446744078004518913
865+
; CHECK-NEXT: [[R:%.*]] = icmp ult i128 [[M]], 39614081257132168796771975168
864866
; CHECK-NEXT: ret i1 [[R]]
865867
;
866868
%z = zext i32 %x to i128

0 commit comments

Comments
 (0)