[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 06:53:49 PDT 2025


================
@@ -920,6 +919,12 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
       Value *Index = GEPToVectorIndex(GEP, &Alloca, VecEltTy, *DL, NewGEPInsts);
       if (!Index)
         return RejectUser(Inst, "cannot compute vector index for GEP");
+      // Alternatively, if there is a constant index for which we already know
+      // that it will be out-of-bounds, we also don't want to promote this
+      // alloca to vector.
+      if (ConstantInt *I = dyn_cast<ConstantInt>(Index);
+          I && I->getZExtValue() >= Alloca.getAllocationSize(*DL))
+        return RejectUser(Inst, "GEP constant index out-of-bounds");
----------------
ro-i wrote:

Well, at least for shufflevector it would crash:
```
opt: /work1/omp-nightly/build/git/trunk21.0/llvm-project/llvm/lib/IR/Instructions.cpp:1756: llvm::ShuffleVectorInst::ShuffleVectorInst(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, const llvm::Twine&, llvm::InsertPosition): Assertion `isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /COD/LATEST/trunk/bin/opt -mtriple amdgcn -passes=amdgpu-promote-alloca-to-vector r.ll -S
1.      Running pass "function(amdgpu-promote-alloca-to-vector)" on module "r.ll"
2.      Running pass "amdgpu-promote-alloca-to-vector" on function "promote_memcpy_two_aggrs"
```
So wouldn't it make more sense to disallow it more broadly?

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


More information about the llvm-commits mailing list