Skip to content

Commit 498ac15

Browse files
committed
[LVI] Address review comments.
1 parent c3bacf0 commit 498ac15

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,13 @@ static void AddNonNullPointersByInstruction(
644644
AddNonNullPointer(MI->getRawDest(), PtrSet);
645645
if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI))
646646
AddNonNullPointer(MTI->getRawSource(), PtrSet);
647+
} else if (auto *CB = dyn_cast<CallBase>(I)) {
648+
for (auto &U : CB->args()) {
649+
if (U->getType()->isPointerTy() &&
650+
CB->paramHasNonNullAttr(CB->getArgOperandNo(&U),
651+
/*AllowUndefOrPoison=*/false))
652+
AddNonNullPointer(U.get(), PtrSet);
653+
}
647654
}
648655
}
649656

@@ -780,25 +787,12 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
780787
}
781788

782789
if (BBLV.isOverdefined()) {
783-
if (PointerType *PTy = dyn_cast<PointerType>(Val->getType())) {
784-
// Check whether we're checking at the terminator, and the pointer has
785-
// been dereferenced in this block.
786-
if (BB->getTerminator() == BBI && isNonNullAtEndOfBlock(Val, BB))
787-
BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
788-
else {
789-
for (Use &U : Val->uses()) {
790-
if (auto *CB = dyn_cast<CallBase>(U.getUser())) {
791-
if (CB->isArgOperand(&U) &&
792-
CB->paramHasNonNullAttr(CB->getArgOperandNo(&U),
793-
/*AllowUndefOrPoison=*/false) &&
794-
isValidAssumeForContext(CB, BBI)) {
795-
BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
796-
break;
797-
}
798-
}
799-
}
800-
}
801-
}
790+
// Check whether we're checking at the terminator, and the pointer has
791+
// been dereferenced in this block.
792+
PointerType *PTy = dyn_cast<PointerType>(Val->getType());
793+
if (PTy && BB->getTerminator() == BBI &&
794+
isNonNullAtEndOfBlock(Val, BB))
795+
BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
802796
}
803797
}
804798

llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ define i1 @test_known_nonnull_at_callsite(ptr %src) {
349349
; CHECK-LABEL: @test_known_nonnull_at_callsite(
350350
; CHECK-NEXT: entry:
351351
; CHECK-NEXT: call void @callee(ptr noundef nonnull [[SRC:%.*]])
352+
; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
352353
; CHECK-NEXT: ret i1 false
353354
;
354355
entry:
@@ -361,6 +362,7 @@ define i1 @test_known_nonnull_mixed(ptr %src) {
361362
; CHECK-LABEL: @test_known_nonnull_mixed(
362363
; CHECK-NEXT: entry:
363364
; CHECK-NEXT: call void @callee2(ptr nonnull [[SRC:%.*]])
365+
; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
364366
; CHECK-NEXT: ret i1 false
365367
;
366368
entry:
@@ -373,6 +375,7 @@ define i1 @test_known_nonnull_at_callsite_dereferenceable(ptr %src) {
373375
; CHECK-LABEL: @test_known_nonnull_at_callsite_dereferenceable(
374376
; CHECK-NEXT: entry:
375377
; CHECK-NEXT: call void @callee(ptr dereferenceable(1) [[SRC:%.*]])
378+
; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
376379
; CHECK-NEXT: ret i1 false
377380
;
378381
entry:

0 commit comments

Comments
 (0)