[llvm] [LAA] Fix inverted bounds for negative-step AddRecs with unknown end. (PR #218388)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 07:49:15 PDT 2026


================
@@ -330,6 +330,22 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap(
   return SE.isKnownPredicate(CmpInst::ICMP_ULE, MaxOffset, DerefBytesSCEV);
 }
 
+/// Return the lowest address of pointer type \p PtrTy, i.e. a null pointer.
+/// Returns nullptr if it cannot be used as a lower bound.
+static const SCEV *getLowestAddress(Type *PtrTy, ScalarEvolution &SE,
+                                    const DataLayout &DL) {
+  if (!DL.getNullPtrValue(PtrTy->getPointerAddressSpace()).isZero())
+    return nullptr;
----------------
nikic wrote:

We don't need a zero null pointer for this, we just need to create a zero pointer here. Currently, using getNullValue() for that is fine, given that the proper alternative for this doesn't exist yet. (You can leave a TODO for it, but using getNullValue is fine at this time. Later it will basically become `inttoptr(0)` if null is not the zero pointer.)

https://github.com/llvm/llvm-project/pull/218388


More information about the llvm-commits mailing list