Skip to content

Commit b3cb99b

Browse files
committed
fixup! [AArch64][GloablISel] Refactor Combine G_CONCAT_VECTOR
1 parent 5e36dff commit b3cb99b

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,15 @@ class CombinerHelper {
227227
/// ==========================================================
228228
/// Check if the G_CONCAT_VECTORS \p MI is undef or if it
229229
/// can be flattened into a build_vector.
230-
/// In the first case \p bool will be true.
231-
/// In the second case \p SmallVector<Register> will contain the operands
230+
/// In the first case \p Ops will be empty
231+
/// In the second case \p Ops will contain the operands
232232
/// needed to produce the flattened build_vector.
233233
///
234234
/// \pre MI.getOpcode() == G_CONCAT_VECTORS.
235-
bool
236-
matchCombineConcatVectors(MachineInstr &MI,
237-
std::pair<bool, SmallVector<Register>> &matchinfo);
238-
/// Replace \p MI with a flattened build_vector with \p SmallVector<Register>
239-
/// or an implicit_def if \p bool is true.
240-
void
241-
applyCombineConcatVectors(MachineInstr &MI,
242-
std::pair<bool, SmallVector<Register>> &matchinfo);
235+
bool matchCombineConcatVectors(MachineInstr &MI, SmallVector<Register> &Ops);
236+
/// Replace \p MI with a flattened build_vector with \p Ops
237+
/// or an implicit_def if \p Ops is empty.
238+
void applyCombineConcatVectors(MachineInstr &MI, SmallVector<Register> &Ops);
243239

244240
/// Try to combine G_SHUFFLE_VECTOR into G_CONCAT_VECTORS.
245241
/// Returns true if MI changed.

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ def match_ors : GICombineRule<
12541254
(apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
12551255

12561256
// Combines concat operations
1257-
def concat_matchinfo : GIDefMatchData<"std::pair<bool, SmallVector<Register>>">;
1257+
def concat_matchinfo : GIDefMatchData<"SmallVector<Register>">;
12581258
def combine_concat_vector : GICombineRule<
12591259
(defs root:$root, concat_matchinfo:$matchinfo),
12601260
(match (wip_match_opcode G_CONCAT_VECTORS):$root,
@@ -1342,4 +1342,4 @@ def all_combines : GICombineGroup<[trivial_combines, insert_vec_elt_combines,
13421342
// compile time performance.
13431343
def optnone_combines : GICombineGroup<[trivial_combines,
13441344
ptr_add_immed_chain, combines_for_extload,
1345-
not_cmp_fold, opt_brcond_by_inverting_cond]>;
1345+
not_cmp_fold, opt_brcond_by_inverting_cond, combine_concat_vector]>;

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ void CombinerHelper::applyCombineCopy(MachineInstr &MI) {
222222
replaceRegWith(MRI, DstReg, SrcReg);
223223
}
224224

225-
bool CombinerHelper::matchCombineConcatVectors(
226-
MachineInstr &MI, std::pair<bool, SmallVector<Register>> &matchinfo) {
225+
bool CombinerHelper::matchCombineConcatVectors(MachineInstr &MI,
226+
SmallVector<Register> &Ops) {
227227
assert(MI.getOpcode() == TargetOpcode::G_CONCAT_VECTORS &&
228228
"Invalid instruction");
229-
matchinfo.first = true;
229+
bool IsUndef = true;
230230
MachineInstr *Undef = nullptr;
231231

232232
// Walk over all the operands of concat vectors and check if they are
@@ -240,11 +240,11 @@ bool CombinerHelper::matchCombineConcatVectors(
240240
return false;
241241
switch (Def->getOpcode()) {
242242
case TargetOpcode::G_BUILD_VECTOR:
243-
matchinfo.first = false;
243+
IsUndef = false;
244244
// Remember the operands of the build_vector to fold
245245
// them into the yet-to-build flattened concat vectors.
246246
for (const MachineOperand &BuildVecMO : Def->uses())
247-
matchinfo.second.push_back(BuildVecMO.getReg());
247+
Ops.push_back(BuildVecMO.getReg());
248248
break;
249249
case TargetOpcode::G_IMPLICIT_DEF: {
250250
LLT OpType = MRI.getType(Reg);
@@ -260,7 +260,7 @@ bool CombinerHelper::matchCombineConcatVectors(
260260
// for the flattening.
261261
for (unsigned EltIdx = 0, EltEnd = OpType.getNumElements();
262262
EltIdx != EltEnd; ++EltIdx)
263-
matchinfo.second.push_back(Undef->getOperand(0).getReg());
263+
Ops.push_back(Undef->getOperand(0).getReg());
264264
break;
265265
}
266266
default:
@@ -270,15 +270,18 @@ bool CombinerHelper::matchCombineConcatVectors(
270270

271271
// Check if the combine is illegal
272272
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])}})) {
275275
return false;
276276
}
277277

278+
if (IsUndef)
279+
Ops.clear();
280+
278281
return true;
279282
}
280-
void CombinerHelper::applyCombineConcatVectors(
281-
MachineInstr &MI, std::pair<bool, SmallVector<Register>> &matchinfo) {
283+
void CombinerHelper::applyCombineConcatVectors(MachineInstr &MI,
284+
SmallVector<Register> &Ops) {
282285
// We determined that the concat_vectors can be flatten.
283286
// Generate the flattened build_vector.
284287
Register DstReg = MI.getOperand(0).getReg();
@@ -291,10 +294,10 @@ void CombinerHelper::applyCombineConcatVectors(
291294
// clean that up. For now, given we already gather this information
292295
// in matchCombineConcatVectors, just save compile time and issue the
293296
// right thing.
294-
if (matchinfo.first)
297+
if (Ops.empty())
295298
Builder.buildUndef(NewDstReg);
296299
else
297-
Builder.buildBuildVector(NewDstReg, matchinfo.second);
300+
Builder.buildBuildVector(NewDstReg, Ops);
298301
MI.eraseFromParent();
299302
replaceRegWith(MRI, DstReg, NewDstReg);
300303
}

llvm/lib/Target/AArch64/AArch64Combine.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def AArch64PreLegalizerCombiner: GICombiner<
6464
}
6565

6666
def AArch64O0PreLegalizerCombiner: GICombiner<
67-
"AArch64O0PreLegalizerCombinerImpl", [optnone_combines, combine_concat_vector]> {
67+
"AArch64O0PreLegalizerCombinerImpl", [optnone_combines]> {
6868
let CombineAllMethodName = "tryCombineAllImpl";
6969
}
7070

0 commit comments

Comments
 (0)