Skip to content

Commit 0748a98

Browse files
committed
[InstCombine] Handle ConstantFoldCompareInstOperands() failure
This function will return nullptr instead of returning a constant expression now, so be sure to handle that. Fixes #93017.
1 parent 9120562 commit 0748a98

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
214214
// Find out if the comparison would be true or false for the i'th element.
215215
Constant *C = ConstantFoldCompareInstOperands(ICI.getPredicate(), Elt,
216216
CompareRHS, DL, &TLI);
217+
if (!C)
218+
return nullptr;
219+
217220
// If the result is undef for this element, ignore it.
218221
if (isa<UndefValue>(C)) {
219222
// Extend range state machines to cover this element in case there is an

llvm/test/Transforms/InstCombine/load-cmp.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,20 @@ define i1 @test10_struct_arr_noinbounds_i64(i64 %x) {
334334
%r = icmp eq i32 %q, 9
335335
ret i1 %r
336336
}
337+
338+
@table = internal constant [2 x ptr] [ptr @g, ptr getelementptr (i8, ptr @g, i64 4)], align 16
339+
@g = external global [2 x i32]
340+
341+
define i1 @pr93017(i64 %idx) {
342+
; CHECK-LABEL: @pr93017(
343+
; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[IDX:%.*]] to i32
344+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @table, i32 0, i32 [[TMP1]]
345+
; CHECK-NEXT: [[V:%.*]] = load ptr, ptr [[GEP]], align 4
346+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[V]], null
347+
; CHECK-NEXT: ret i1 [[CMP]]
348+
;
349+
%gep = getelementptr inbounds [2 x ptr], ptr @table, i64 0, i64 %idx
350+
%v = load ptr, ptr %gep
351+
%cmp = icmp ne ptr %v, null
352+
ret i1 %cmp
353+
}

0 commit comments

Comments
 (0)