Skip to content

Commit 989d82e

Browse files
committed
Refactor visitExtractElementInst and visitInsertElementInst
1 parent 4c28344 commit 989d82e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

llvm/lib/Target/DirectX/DXILDataScalarization.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,36 +188,38 @@ allocaArrayFromVector(IRBuilder<> &Builder, Value *Vec, Type *IdxTy) {
188188
return std::make_pair(ArrAlloca, ArrTy);
189189
}
190190

191-
bool DataScalarizerVisitor::visitInsertElementInst(InsertElementInst &IEI) {
191+
static bool replaceDynamicInsertElementInst(InsertElementInst &IEI) {
192+
IRBuilder<> Builder(&IEI);
193+
192194
Value *Vec = IEI.getOperand(0);
193195
Value *Val = IEI.getOperand(1);
194196
Value *Index = IEI.getOperand(2);
195197
Type *IndexTy = Index->getType();
196198

197-
// If the index is a constant then we don't need to scalarize it
198-
if (isa<ConstantInt>(Index))
199-
return false;
200-
201-
IRBuilder<> Builder(&IEI);
202199
std::pair<Value *, Type *> Arr = allocaArrayFromVector(Builder, Vec, IndexTy);
203200
Value *ArrAlloca = Arr.first;
204201
Type *ArrTy = Arr.second;
205202
Value *GEP = Builder.CreateInBoundsGEP(ArrTy, ArrAlloca,
206203
{ConstantInt::get(IndexTy, 0), Index});
207204
Builder.CreateStore(Val, GEP);
208-
209205
IEI.eraseFromParent();
210206
return true;
211207
}
212208

213-
bool DataScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
209+
bool DataScalarizerVisitor::visitInsertElementInst(InsertElementInst &IEI) {
214210
// If the index is a constant then we don't need to scalarize it
215-
Value *Index = EEI.getIndexOperand();
216-
Type *IndexTy = Index->getType();
211+
Value *Index = IEI.getOperand(2);
217212
if (isa<ConstantInt>(Index))
218213
return false;
214+
return replaceDynamicInsertElementInst(IEI);
215+
}
219216

217+
static bool replaceDynamicExtractElementInst(ExtractElementInst &EEI) {
220218
IRBuilder<> Builder(&EEI);
219+
220+
Value *Index = EEI.getIndexOperand();
221+
Type *IndexTy = Index->getType();
222+
221223
std::pair<Value *, Type *> Arr =
222224
allocaArrayFromVector(Builder, EEI.getVectorOperand(), IndexTy);
223225
Value *ArrAlloca = Arr.first;
@@ -232,6 +234,14 @@ bool DataScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
232234
return true;
233235
}
234236

237+
bool DataScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
238+
// If the index is a constant then we don't need to scalarize it
239+
Value *Index = EEI.getIndexOperand();
240+
if (isa<ConstantInt>(Index))
241+
return false;
242+
return replaceDynamicExtractElementInst(EEI);
243+
}
244+
235245
bool DataScalarizerVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
236246

237247
unsigned NumOperands = GEPI.getNumOperands();

0 commit comments

Comments
 (0)