Skip to content

Commit 3cc1dc5

Browse files
committed
Don't bother looking through gep inbounds
1 parent 0ddf227 commit 3cc1dc5

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

llvm/lib/Analysis/CaptureTracking.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,8 @@ CaptureInfo llvm::DetermineUseCaptureKind(
400400
}
401401

402402
// Check whether this is a comparison of the base pointer against
403-
// null. We can also strip inbounds GEPs, as inbounds preserves
404-
// the null-ness of the pointer.
405-
Value *Stripped = U.get();
406-
if (!NullPointerIsDefined(I->getFunction(),
407-
U->getType()->getPointerAddressSpace()))
408-
Stripped = Stripped->stripInBoundsOffsets();
409-
if (Stripped == Base)
403+
// null.
404+
if (U.get() == Base)
410405
return CaptureInfo::otherOnly(CaptureComponents::AddressIsNull);
411406
}
412407

llvm/test/Transforms/FunctionAttrs/nocapture.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,12 @@ define i1 @captureICmpWrongPred(ptr %x) {
788788
ret i1 %1
789789
}
790790

791+
; We could infer captures(address_is_null) here, but don't bother, because
792+
; InstCombine will optimize the GEP away.
791793
define i1 @nocaptureInboundsGEPICmp(ptr %x) {
792794
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
793795
; FNATTRS-LABEL: define i1 @nocaptureInboundsGEPICmp
794-
; FNATTRS-SAME: (ptr readnone captures(address_is_null) [[X:%.*]]) #[[ATTR0]] {
796+
; FNATTRS-SAME: (ptr readnone captures(address) [[X:%.*]]) #[[ATTR0]] {
795797
; FNATTRS-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 5
796798
; FNATTRS-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP1]], null
797799
; FNATTRS-NEXT: ret i1 [[TMP2]]
@@ -811,7 +813,7 @@ define i1 @nocaptureInboundsGEPICmp(ptr %x) {
811813
define i1 @nocaptureInboundsGEPICmpRev(ptr %x) {
812814
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
813815
; FNATTRS-LABEL: define i1 @nocaptureInboundsGEPICmpRev
814-
; FNATTRS-SAME: (ptr readnone captures(address_is_null) [[X:%.*]]) #[[ATTR0]] {
816+
; FNATTRS-SAME: (ptr readnone captures(address) [[X:%.*]]) #[[ATTR0]] {
815817
; FNATTRS-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 5
816818
; FNATTRS-NEXT: [[TMP2:%.*]] = icmp eq ptr null, [[TMP1]]
817819
; FNATTRS-NEXT: ret i1 [[TMP2]]

0 commit comments

Comments
 (0)