[llvm] [DirectX] remove getAllocatedType in DXILDataScalarization (PR #179067)

Jameson Nash via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 31 12:53:52 PST 2026


https://github.com/vtjnash created https://github.com/llvm/llvm-project/pull/179067

Update dynamicallyLoadArray to take the allocated type as a parameter instead of querying getAllocatedType. This is to facilitate removing other incorrect uses of getAllocatedType, and eventually possibly even getAllocatedType itself.

>From 2a1a294109ed14195c24b601537b972b41a46a98 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash+github at gmail.com>
Date: Wed, 28 Jan 2026 16:16:04 +0000
Subject: [PATCH] [DirectX] remove getAllocatedType in DXILDataScalarization

Update dynamicallyLoadArray to take the allocated type as a parameter
instead of querying getAllocatedType. This is to facilitate removing
incorrect uses of getAllocatedType, and eventually possibly even
getAllocatedType itself.

Co-Authored-By: Claude Sonnet 4.5 <noreply at anthropic.com>
---
 .../Target/DirectX/DXILDataScalarization.cpp  | 25 ++++++++++---------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Target/DirectX/DXILDataScalarization.cpp b/llvm/lib/Target/DirectX/DXILDataScalarization.cpp
index 5f18c37ef1125..f805ed1f2bddc 100644
--- a/llvm/lib/Target/DirectX/DXILDataScalarization.cpp
+++ b/llvm/lib/Target/DirectX/DXILDataScalarization.cpp
@@ -67,7 +67,8 @@ class DataScalarizerVisitor : public InstVisitor<DataScalarizerVisitor, bool> {
   friend bool findAndReplaceVectors(llvm::Module &M);
 
 private:
-  typedef std::pair<AllocaInst *, SmallVector<Value *, 4>> AllocaAndGEPs;
+  typedef std::tuple<AllocaInst *, Type *, SmallVector<Value *, 4>>
+      AllocaAndGEPs;
   typedef SmallDenseMap<Value *, AllocaAndGEPs>
       VectorToArrayMap; // A map from a vector-typed Value to its corresponding
                         // AllocaInst and GEPs to each element of an array
@@ -211,17 +212,16 @@ DataScalarizerVisitor::createArrayFromVector(IRBuilder<> &Builder, Value *Vec,
     Builder.CreateStore(EE, GEPs[I]);
   }
 
-  VectorAllocaMap.insert({Vec, {ArrAlloca, GEPs}});
+  VectorAllocaMap.insert({Vec, {ArrAlloca, ArrTy, GEPs}});
   Builder.SetInsertPoint(InsertPoint);
-  return {ArrAlloca, GEPs};
+  return {ArrAlloca, ArrTy, GEPs};
 }
 
 /// Returns a pair of Value* with the first being a GEP into ArrAlloca using
 /// indices {0, Index}, and the second Value* being a Load of the GEP
 static std::pair<Value *, Value *>
-dynamicallyLoadArray(IRBuilder<> &Builder, AllocaInst *ArrAlloca, Value *Index,
-                     const Twine &Name = "") {
-  Type *ArrTy = ArrAlloca->getAllocatedType();
+dynamicallyLoadArray(IRBuilder<> &Builder, AllocaInst *ArrAlloca, Type *ArrTy,
+                     Value *Index, const Twine &Name = "") {
   Value *GEP = Builder.CreateInBoundsGEP(
       ArrTy, ArrAlloca, {Builder.getInt32(0), Index}, Name + ".index");
   Value *Load =
@@ -239,12 +239,12 @@ bool DataScalarizerVisitor::replaceDynamicInsertElementInst(
 
   AllocaAndGEPs ArrAllocaAndGEPs =
       createArrayFromVector(Builder, Vec, IEI.getName());
-  AllocaInst *ArrAlloca = ArrAllocaAndGEPs.first;
-  Type *ArrTy = ArrAlloca->getAllocatedType();
-  SmallVector<Value *, 4> &ArrGEPs = ArrAllocaAndGEPs.second;
+  AllocaInst *ArrAlloca = ArrAllocaAndGEPs.get<0>();
+  Type *ArrTy = ArrAllocaAndGEPs.get<1>();
+  SmallVector<Value *, 4> &ArrGEPs = ArrAllocaAndGEPs.get<2>();
 
   auto GEPAndLoad =
-      dynamicallyLoadArray(Builder, ArrAlloca, Index, IEI.getName());
+      dynamicallyLoadArray(Builder, ArrAlloca, ArrTy, Index, IEI.getName());
   Value *GEP = GEPAndLoad.first;
   Value *Load = GEPAndLoad.second;
 
@@ -280,9 +280,10 @@ bool DataScalarizerVisitor::replaceDynamicExtractElementInst(
 
   AllocaAndGEPs ArrAllocaAndGEPs =
       createArrayFromVector(Builder, EEI.getVectorOperand(), EEI.getName());
-  AllocaInst *ArrAlloca = ArrAllocaAndGEPs.first;
+  AllocaInst *ArrAlloca = ArrAllocaAndGEPs.get<0>();
+  Type *ArrTy = ArrAllocaAndGEPs.get<1>();
 
-  auto GEPAndLoad = dynamicallyLoadArray(Builder, ArrAlloca,
+  auto GEPAndLoad = dynamicallyLoadArray(Builder, ArrAlloca, ArrTy,
                                          EEI.getIndexOperand(), EEI.getName());
   Value *Load = GEPAndLoad.second;
 



More information about the llvm-commits mailing list