Skip to content

Commit e55b9de

Browse files
committed
[InstCombine] Add one-use constraint for the simplification
1 parent 3a386e3 commit e55b9de

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ Instruction *InstCombinerImpl::foldICmpDivConstant(ICmpInst &Cmp,
26502650
// icmp ugt (sdiv exact X, C2), (sdiv signed_max, C2) --> icmp slt X, 0
26512651
// icmp ult (sdiv exact X, C2), (sdiv signed_max, C2) + 1 --> icmp sgt X, -1
26522652
// where C2 is positive.
2653-
if (DivIsSigned && Div->isExact() &&
2653+
if (DivIsSigned && Div->hasOneUse() && Div->isExact() &&
26542654
(Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_ULT) &&
26552655
C2->isStrictlyPositive() &&
26562656
APInt::getSignedMaxValue(C2->getBitWidth()).sdiv(*C2) +

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5232,3 +5232,16 @@ define i1 @icmp_ugt_sdiv_by_negative_constant(i64 %x) {
52325232
%cmp = icmp ugt i64 %sdiv, -384307168202282326
52335233
ret i1 %cmp
52345234
}
5235+
5236+
define i1 @icmp_ugt_sdiv_by_constant_multiuse(i64 %x) {
5237+
; CHECK-LABEL: @icmp_ugt_sdiv_by_constant_multiuse(
5238+
; CHECK-NEXT: [[SDIV:%.*]] = sdiv exact i64 [[X:%.*]], 24
5239+
; CHECK-NEXT: call void @use_i64(i64 [[SDIV]])
5240+
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[SDIV]], 384307168202282325
5241+
; CHECK-NEXT: ret i1 [[CMP]]
5242+
;
5243+
%sdiv = sdiv exact i64 %x, 24
5244+
call void @use_i64(i64 %sdiv)
5245+
%cmp = icmp ugt i64 %sdiv, 384307168202282325
5246+
ret i1 %cmp
5247+
}

0 commit comments

Comments
 (0)