Skip to content

Commit d23da7d

Browse files
authored
1 parent 44d1dbd commit d23da7d

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,8 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
996996
if (!V->hasOneUse())
997997
return nullptr;
998998

999-
if (Depth == 1)
999+
constexpr unsigned RecursionLimit = 3;
1000+
if (Depth == RecursionLimit)
10001001
return nullptr;
10011002

10021003
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {

llvm/test/Transforms/InstCombine/load.ll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,33 @@ define i32 @load_select_with_null_gep(i1 %cond, ptr %p, i64 %off) {
451451
%res = load i32, ptr %gep, align 4
452452
ret i32 %res
453453
}
454+
455+
define i16 @load_select_with_null_gep2(i1 %cond, ptr %p, i64 %x) {
456+
; CHECK-LABEL: @load_select_with_null_gep2(
457+
; CHECK-NEXT: [[INVARIANT_GEP:%.*]] = getelementptr i8, ptr [[SEL:%.*]], i64 -2
458+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[INVARIANT_GEP]], i64 [[X:%.*]]
459+
; CHECK-NEXT: [[RES:%.*]] = load i16, ptr [[GEP]], align 2
460+
; CHECK-NEXT: ret i16 [[RES]]
461+
;
462+
%sel = select i1 %cond, ptr %p, ptr null
463+
%invariant.gep = getelementptr i8, ptr %sel, i64 -2
464+
%gep = getelementptr i16, ptr %invariant.gep, i64 %x
465+
%res = load i16, ptr %gep, align 2
466+
ret i16 %res
467+
}
468+
469+
define i16 @load_select_with_null_gep3(i1 %cond, ptr %p, i64 %x, i64 %y) {
470+
; CHECK-LABEL: @load_select_with_null_gep3(
471+
; CHECK-NEXT: [[INVARIANT_GEP:%.*]] = getelementptr i8, ptr [[SEL:%.*]], i64 -2
472+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[INVARIANT_GEP]], i64 [[X:%.*]]
473+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i16, ptr [[GEP]], i64 [[Y:%.*]]
474+
; CHECK-NEXT: [[RES:%.*]] = load i16, ptr [[GEP2]], align 2
475+
; CHECK-NEXT: ret i16 [[RES]]
476+
;
477+
%sel = select i1 %cond, ptr %p, ptr null
478+
%invariant.gep = getelementptr i8, ptr %sel, i64 -2
479+
%gep = getelementptr i16, ptr %invariant.gep, i64 %x
480+
%gep2 = getelementptr i16, ptr %gep, i64 %y
481+
%res = load i16, ptr %gep2, align 2
482+
ret i16 %res
483+
}

0 commit comments

Comments
 (0)