[llvm] [DirectX] Reland #142853 with Circular GEP fixes (PR #143747)
Finn Plummer via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 08:19:54 PDT 2025
================
@@ -271,10 +275,18 @@ bool DXILFlattenArraysVisitor::visitGetElementPtrInstInGEPChainBase(
genInstructionFlattenIndices(GEPInfo.Indices, GEPInfo.Dims, Builder);
ArrayType *FlattenedArrayType = GEPInfo.ParentArrayType;
- Value *FlatGEP =
- Builder.CreateGEP(FlattenedArrayType, GEPInfo.ParendOperand,
- {Builder.getInt32(0), FlatIndex},
- GEP.getName() + ".flat", GEP.getNoWrapFlags());
+
+ // Don't append '.flat' to an empty string. If the SSA name isn't available
+ // it could conflict with the ParentOperand's name.
+ std::string FlatName = GEP.hasName() ? GEP.getName().str() + ".flat" : "";
+
+ Value *FlatGEP = Builder.CreateGEP(FlattenedArrayType, GEPInfo.ParentOperand,
+ {Builder.getInt32(0), FlatIndex}, FlatName,
+ GEP.getNoWrapFlags());
+
+ // Store the new GEP in the map before replacing uses to avoid circular
+ // references
+ GEPChainMap.erase(&GEP);
----------------
inbelic wrote:
I don't think I understand the comment here with the code correctly.
Is this intended to also insert `FlatGEP` to `GEPChainMap`?
https://github.com/llvm/llvm-project/pull/143747
More information about the llvm-commits
mailing list