[llvm] [DirectX] Scalarize `extractelement` and `insertelement` with dynamic indices (PR #141676)
Finn Plummer via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 19 11:37:09 PDT 2025
================
@@ -173,6 +183,125 @@ bool DataScalarizerVisitor::visitStoreInst(StoreInst &SI) {
return false;
}
+DataScalarizerVisitor::AllocaAndGEPs
+DataScalarizerVisitor::createArrayFromVector(IRBuilder<> &Builder, Value *Vec,
+ const Twine &Name = "") {
+ // If there is already an alloca for this vector, return it
+ auto VA = VectorAllocaMap.find(Vec);
+ if (VA != VectorAllocaMap.end())
+ return VA->second;
+
+ auto InsertPoint = Builder.GetInsertPoint();
+
+ // Allocate the array to hold the vector elements
+ Builder.SetInsertPointPastAllocas(Builder.GetInsertBlock()->getParent());
+ Type *ArrTy = equivalentArrayTypeFromVector(Vec->getType());
+ AllocaInst *ArrAlloca =
+ Builder.CreateAlloca(ArrTy, nullptr, Name + ".alloca");
+ const uint64_t ArrNumElems = ArrTy->getArrayNumElements();
----------------
inbelic wrote:
nit:
```suggestion
const uint64_t ArrNumElems = ArrTy->getArrayNumElements();
assert(ArrNumElems =< 4 && "For vectors larger than 4, dynamic indexing must be natively supported.");
```
We could also use `Value *[4]` instead of the `SmallVector` if we want to be strict on our assumption above.
https://github.com/llvm/llvm-project/pull/141676
More information about the llvm-commits
mailing list