[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.

Chandler Carruth chandlerc at gmail.com
Tue Dec 4 09:52:14 PST 2012


  PTAL


================
Comment at: lib/Analysis/ValueTracking.cpp:893
@@ +892,3 @@
+    if ((!OpC && !isKnownNonZero(GTI.getOperand(), DL, Depth++)) ||
+        OpC->isZero())
+      continue;
----------------
Benjamin Kramer wrote:
> 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
>   }
I knew i meant to include that test case for a reason... =D Thanks!

================
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);
----------------
Benjamin Kramer wrote:
> What will this do for structs that contain only one element?
It's dead code. I've made this simpler with an assert. =]

================
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.
----------------
Benjamin Kramer wrote:
> typo: poniter
Fixed!


http://llvm-reviews.chandlerc.com/D160



More information about the llvm-commits mailing list