[llvm-commits] [PATCH] Add support to ValueTracking for determining that a pointer is non-null by virtue of inbounds GEPs that preclude a null pointer.
Benjamin Kramer
benny.kra at gmail.com
Tue Dec 4 06:05:48 PST 2012
================
Comment at: lib/Analysis/ValueTracking.cpp:876
@@ +875,3 @@
+
+ // If the base poniter is non-null, we cannot walk to a null address with an
+ // inbounds GEP in address space zero.
----------------
typo: poniter
================
Comment at: lib/Analysis/ValueTracking.cpp:893
@@ +892,3 @@
+ if ((!OpC && !isKnownNonZero(GTI.getOperand(), DL, Depth++)) ||
+ OpC->isZero())
+ continue;
----------------
This calls `isZero` on a NULL pointer if `OpC = NULL` and `isKnownNonZero(GTI.getOperand(), DL, Depth++) = true`.
Test case:
define i1 @test(i8* %ptr, i32 %a) {
%b = or i32 %a, 1
%x = getelementptr inbounds i8* %ptr, i32 %b
%cmp = icmp eq i8* %x, null
ret i1 %cmp
}
================
Comment at: lib/Analysis/ValueTracking.cpp:897
@@ +896,3 @@
+ if (StructType *STy = dyn_cast<StructType>(*GTI)) {
+ unsigned ElementIdx = OpC ? OpC->getZExtValue() : 1;
+ const StructLayout *SL = DL->getStructLayout(STy);
----------------
What will this do for structs that contain only one element?
http://llvm-reviews.chandlerc.com/D160
More information about the llvm-commits
mailing list