[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 13:43:36 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:

Just to make sure this is the intended implementation: this will always check index 2 onwards, since I start at 1, and you are adding 1 to it when getting the operands. 

The comments, made me confused, so want to double-check you are intentionally skipping index 1.

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


More information about the llvm-commits mailing list