[llvm] [AMDGPU] Support i8/i16 GEP indices when promoting allocas to vectors (PR #175489)
Carl Ritson via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 19:50:01 PST 2026
================
@@ -551,33 +556,61 @@ computeGEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
if (VarOffsets.size() > 1)
return {};
- APInt IndexQuot;
- int64_t Rem;
- APInt::sdivrem(ConstOffset, VecElemSize, IndexQuot, Rem);
- if (Rem != 0)
+ // We support vector indices of the form ((A * stride) >> shift) + B.
+ // IndexQuot represents B. Check that the constant offset is a multiple
+ // of the vector element size.
+ if (ConstOffset.srem(VecElemSize) != 0)
return {};
+ APInt IndexQuot = ConstOffset.sdiv(VecElemSize);
GEPToVectorIndex Result;
if (!ConstOffset.isZero())
Result.ConstIndex = ConstantInt::get(Ctx, IndexQuot.sextOrTrunc(BW));
+ // If there are no variable offsets, only a constant offset, then we're done.
if (VarOffsets.empty())
return Result;
+ // Scale is the stride in the (A * stride) part. Check that there is only one
+ // variable offset and extract the scale factor.
const auto &VarOffset = VarOffsets.front();
- APInt OffsetQuot;
- APInt::sdivrem(VarOffset.second, VecElemSize, OffsetQuot, Rem);
- if (Rem != 0 || OffsetQuot.isZero())
+ uint64_t Scale = VarOffset.second.getZExtValue();
----------------
perlfu wrote:
Is zext really the right thing to do here?
I am imagining perhaps Scale is signed, in which case the code below does not handle correctly.
Perhaps you should early out on `isSignBitSet`?
https://github.com/llvm/llvm-project/pull/175489
More information about the llvm-commits
mailing list