[llvm] [DirectX] Fix bug where Flatten arrays was only using last index (PR #144146)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 13 14:01:20 PDT 2025


================
@@ -218,6 +225,29 @@ bool DXILFlattenArraysVisitor::visitAllocaInst(AllocaInst &AI) {
   return true;
 }
 
+void DXILFlattenArraysVisitor::collectIndicesAndDimsFromGEP(
+    GetElementPtrInst &GEP, SmallVectorImpl<Value *> &Indices,
+    SmallVectorImpl<uint64_t> &Dims, bool &AllIndicesAreConstInt) {
+
+  // Skip the first index (which is ptr index ie always start at 0 for arrays)
+  // and collect all subsequent indices
+  Type *CurrentType = GEP.getSourceElementType();
+  for (unsigned I = 1; I < GEP.getNumIndices(); ++I) {
+    Value *Index = GEP.getOperand(I + 1); // +1 because operand 0 is the pointer
----------------
joaosaffran wrote:

Gotcha, can we make this clear in the comments, please

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


More information about the llvm-commits mailing list