Skip to content

Commit 74f0229

Browse files
committed
[InnstCombine] Fix assertion failure on trivial cases
1 parent 5db2438 commit 74f0229

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ static Instruction *foldICmpShlLHSC(ICmpInst &Cmp, Instruction *Shl,
22392239
unsigned TypeBits = C.getBitWidth();
22402240
ICmpInst::Predicate Pred = Cmp.getPredicate();
22412241
if (Cmp.isUnsigned()) {
2242-
assert(!C2->isZero() && C2->ult(C) &&
2242+
assert(!C2->isZero() && C2->ule(C) &&
22432243
"Should be simplified by InstSimplify");
22442244
APInt Div, Rem;
22452245
APInt::udivrem(C, *C2, Div, Rem);

llvm/test/Transforms/InstCombine/icmp-shl-nuw.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,13 @@ define i1 @fold_icmp_shl_nuw_c2_precondition2(i32 %x) {
176176
%cmp = icmp ult i32 %shl, 63
177177
ret i1 %cmp
178178
}
179+
180+
; Make sure we don't crash on this case.
181+
define i1 @fold_icmp_shl_nuw_c2_precondition3(i32 %x) {
182+
; CHECK-LABEL: @fold_icmp_shl_nuw_c2_precondition3(
183+
; CHECK-NEXT: ret i1 false
184+
;
185+
%shl = shl nuw i32 1, %x
186+
%cmp = icmp ult i32 %shl, 1
187+
ret i1 %cmp
188+
}

0 commit comments

Comments
 (0)