[llvm] [HLSL][DirectX] Handles GEPs in dxil resource access pass (PR #224754)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 14:58:27 PDT 2026
================
@@ -665,9 +666,27 @@ static void createCBufferLoad(IntrinsicInst *II, LoadInst *LI,
// because arrays and structs are always row aligned, and accesses to
// vector elements will show up as a load of the vector followed by an
// extractelement.
+ Value *RowIndex = *LastGEP->idx_begin();
+ uint64_t IndexScale =
+ DL.getTypeAllocSize(LastGEP->getSourceElementType());
+ if (IndexScale < hlsl::CBufferRowSizeInBytes) {
+ assert(hlsl::CBufferRowSizeInBytes % IndexScale == 0 &&
+ "CBuffer GEP index is not row aligned");
+ RowIndex = Builder.CreateExactUDiv(
+ RowIndex,
+ ConstantInt::get(Builder.getInt32Ty(),
+ hlsl::CBufferRowSizeInBytes / IndexScale));
----------------
farzonl wrote:
Don't do `.getInt32Ty()` the legalizer has a i64 to i32 downgrader and we should just depend on that. But the reason not to do this is GEP indices (RowIndex) are frequently 64-bit integers (i64). If you pass an i32 constant from Builder.getInt32Ty() as the right-hand side to CreateExactUDiv or CreateMul, LLVM will hit an assertion failure for type mismatch (Div operands must have the same type!).
```suggestion
ConstantInt:::get(IndexTy, hlsl::CBufferRowSizeInBytes / IndexScale));
```
https://github.com/llvm/llvm-project/pull/224754
More information about the llvm-commits
mailing list