[llvm] [AMDGPU] PromoteAlloca: reject known out-of-bounds index (PR #139700)

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 04:20:21 PDT 2025


================
@@ -438,7 +438,8 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
   SmallMapVector<Value *, APInt, 4> VarOffsets;
   APInt ConstOffset(BW, 0);
   if (GEP->getPointerOperand()->stripPointerCasts() != Alloca ||
-      !GEP->collectOffset(DL, BW, VarOffsets, ConstOffset))
+      !GEP->collectOffset(DL, BW, VarOffsets, ConstOffset) ||
+      ConstOffset.getZExtValue() >= Alloca->getAllocationSize(DL))
----------------
ro-i wrote:

I feel like this is the point where things start to go wrong The situation in which `GEPToVectorIndex` is called looks like this:

https://github.com/llvm/llvm-project/blob/9b63bdd15418e90d0c6889d26e490db89ae744d1/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp#L916-L927

> // If we can't compute a vector index from this GEP, then we can't
> // promote this alloca to vector.

Doesn't this include what I'd like to achieve?

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


More information about the llvm-commits mailing list