@@ -222,11 +222,11 @@ void CombinerHelper::applyCombineCopy(MachineInstr &MI) {
222
222
replaceRegWith (MRI, DstReg, SrcReg);
223
223
}
224
224
225
- bool CombinerHelper::matchCombineConcatVectors (
226
- MachineInstr &MI, std::pair< bool , SmallVector<Register>> &matchinfo ) {
225
+ bool CombinerHelper::matchCombineConcatVectors (MachineInstr &MI,
226
+ SmallVector<Register> &Ops ) {
227
227
assert (MI.getOpcode () == TargetOpcode::G_CONCAT_VECTORS &&
228
228
" Invalid instruction" );
229
- matchinfo. first = true ;
229
+ bool IsUndef = true ;
230
230
MachineInstr *Undef = nullptr ;
231
231
232
232
// Walk over all the operands of concat vectors and check if they are
@@ -240,11 +240,11 @@ bool CombinerHelper::matchCombineConcatVectors(
240
240
return false ;
241
241
switch (Def->getOpcode ()) {
242
242
case TargetOpcode::G_BUILD_VECTOR:
243
- matchinfo. first = false ;
243
+ IsUndef = false ;
244
244
// Remember the operands of the build_vector to fold
245
245
// them into the yet-to-build flattened concat vectors.
246
246
for (const MachineOperand &BuildVecMO : Def->uses ())
247
- matchinfo. second .push_back (BuildVecMO.getReg ());
247
+ Ops .push_back (BuildVecMO.getReg ());
248
248
break ;
249
249
case TargetOpcode::G_IMPLICIT_DEF: {
250
250
LLT OpType = MRI.getType (Reg);
@@ -260,7 +260,7 @@ bool CombinerHelper::matchCombineConcatVectors(
260
260
// for the flattening.
261
261
for (unsigned EltIdx = 0 , EltEnd = OpType.getNumElements ();
262
262
EltIdx != EltEnd; ++EltIdx)
263
- matchinfo. second .push_back (Undef->getOperand (0 ).getReg ());
263
+ Ops .push_back (Undef->getOperand (0 ).getReg ());
264
264
break ;
265
265
}
266
266
default :
@@ -270,15 +270,18 @@ bool CombinerHelper::matchCombineConcatVectors(
270
270
271
271
// Check if the combine is illegal
272
272
LLT DstTy = MRI.getType (MI.getOperand (0 ).getReg ());
273
- if (!isLegalOrBeforeLegalizer ({TargetOpcode::G_BUILD_VECTOR,
274
- {DstTy, MRI.getType (matchinfo. second [0 ])}})) {
273
+ if (!isLegalOrBeforeLegalizer (
274
+ {TargetOpcode::G_BUILD_VECTOR, {DstTy, MRI.getType (Ops [0 ])}})) {
275
275
return false ;
276
276
}
277
277
278
+ if (IsUndef)
279
+ Ops.clear ();
280
+
278
281
return true ;
279
282
}
280
- void CombinerHelper::applyCombineConcatVectors (
281
- MachineInstr &MI, std::pair< bool , SmallVector<Register>> &matchinfo ) {
283
+ void CombinerHelper::applyCombineConcatVectors (MachineInstr &MI,
284
+ SmallVector<Register> &Ops ) {
282
285
// We determined that the concat_vectors can be flatten.
283
286
// Generate the flattened build_vector.
284
287
Register DstReg = MI.getOperand (0 ).getReg ();
@@ -291,10 +294,10 @@ void CombinerHelper::applyCombineConcatVectors(
291
294
// clean that up. For now, given we already gather this information
292
295
// in matchCombineConcatVectors, just save compile time and issue the
293
296
// right thing.
294
- if (matchinfo. first )
297
+ if (Ops. empty () )
295
298
Builder.buildUndef (NewDstReg);
296
299
else
297
- Builder.buildBuildVector (NewDstReg, matchinfo. second );
300
+ Builder.buildBuildVector (NewDstReg, Ops );
298
301
MI.eraseFromParent ();
299
302
replaceRegWith (MRI, DstReg, NewDstReg);
300
303
}
0 commit comments