@@ -188,36 +188,38 @@ allocaArrayFromVector(IRBuilder<> &Builder, Value *Vec, Type *IdxTy) {
188
188
return std::make_pair (ArrAlloca, ArrTy);
189
189
}
190
190
191
- bool DataScalarizerVisitor::visitInsertElementInst (InsertElementInst &IEI) {
191
+ static bool replaceDynamicInsertElementInst (InsertElementInst &IEI) {
192
+ IRBuilder<> Builder (&IEI);
193
+
192
194
Value *Vec = IEI.getOperand (0 );
193
195
Value *Val = IEI.getOperand (1 );
194
196
Value *Index = IEI.getOperand (2 );
195
197
Type *IndexTy = Index->getType ();
196
198
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);
202
199
std::pair<Value *, Type *> Arr = allocaArrayFromVector (Builder, Vec, IndexTy);
203
200
Value *ArrAlloca = Arr.first ;
204
201
Type *ArrTy = Arr.second ;
205
202
Value *GEP = Builder.CreateInBoundsGEP (ArrTy, ArrAlloca,
206
203
{ConstantInt::get (IndexTy, 0 ), Index});
207
204
Builder.CreateStore (Val, GEP);
208
-
209
205
IEI.eraseFromParent ();
210
206
return true ;
211
207
}
212
208
213
- bool DataScalarizerVisitor::visitExtractElementInst (ExtractElementInst &EEI ) {
209
+ bool DataScalarizerVisitor::visitInsertElementInst (InsertElementInst &IEI ) {
214
210
// 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 );
217
212
if (isa<ConstantInt>(Index))
218
213
return false ;
214
+ return replaceDynamicInsertElementInst (IEI);
215
+ }
219
216
217
+ static bool replaceDynamicExtractElementInst (ExtractElementInst &EEI) {
220
218
IRBuilder<> Builder (&EEI);
219
+
220
+ Value *Index = EEI.getIndexOperand ();
221
+ Type *IndexTy = Index->getType ();
222
+
221
223
std::pair<Value *, Type *> Arr =
222
224
allocaArrayFromVector (Builder, EEI.getVectorOperand (), IndexTy);
223
225
Value *ArrAlloca = Arr.first ;
@@ -232,6 +234,14 @@ bool DataScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
232
234
return true ;
233
235
}
234
236
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
+
235
245
bool DataScalarizerVisitor::visitGetElementPtrInst (GetElementPtrInst &GEPI) {
236
246
237
247
unsigned NumOperands = GEPI.getNumOperands ();
0 commit comments