[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.
Duncan Sands
baldrick at free.fr
Fri Dec 7 09:25:00 PST 2012
Hi Chandler,
> --- lib/Analysis/ValueTracking.cpp
> +++ lib/Analysis/ValueTracking.cpp
> @@ -885,26 +890,28 @@
> // inherently violate the inbounds contract within address space zero.
> for (gep_type_iterator GTI = gep_type_begin(GEP), GTE = gep_type_end(GEP);
> GTI != GTE; ++GTI) {
> - ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
> - if (!OpC && Depth >= MaxDepth)
> - return false;
> -
> - // If we have a non-zero constant or a known-non-zero value, we can try to
> - // reason about the GEP.
> - if ((!OpC && !isKnownNonZero(GTI.getOperand(), DL, Depth++)) ||
> - (OpC && OpC->isZero()))
> - continue;
> -
> + // Struct types are easy -- they must always be indexed by a constant.
> if (StructType *STy = dyn_cast<StructType>(*GTI)) {
> - assert(OpC && "Only constants can index a struct!");
> + ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
> unsigned ElementIdx = OpC->getZExtValue();
> const StructLayout *SL = DL->getStructLayout(STy);
> uint64_t ElementOffset = SL->getElementOffset(ElementIdx);
> if (ElementOffset > 0)
> return true;
> - } else if (DL->getTypeAllocSize(GTI.getIndexedType()) > 0) {
> - return true;
> + continue;
> }
> +
> + // If we have a zero-sized type, the index doesn't matter. Keep looing.
looing -> looking.
Otherwise looks great to me. Thanks for making the changes!
Ciao, Duncan.
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
http://llvm-reviews.chandlerc.com/D160
More information about the llvm-commits
mailing list