Skip to content

Commit d504624

Browse files
committed
[NFC][AIE2PS] Refactor: extract setInsertPtAfterInstr helper in AIECombinerHelper
The insertion-point setup logic (advance past an instruction, skip any immediately-following PHI nodes, call MachineIRBuilder::setInsertPt) was duplicated verbatim in two combiner lambdas: - matchChainedPtrAddWithNonConstOffsets - matchPostIncLoadStorePtrAddWithTrunc Extract it into a file-local static helper `setInsertPtAfterInstr` and replace both call sites.
1 parent b5bfeaf commit d504624

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

llvm/lib/Target/AIE/AIECombinerHelper.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,18 @@ static std::optional<Register> getSourceFromS20(Register S20Reg,
14071407
return std::nullopt;
14081408
}
14091409

1410+
/// Set the insertion point of \p B to right after \p InsertionPoint,
1411+
/// skipping any PHI nodes that immediately follow it.
1412+
static void setInsertPtAfterInstr(MachineIRBuilder &B,
1413+
MachineInstr *InsertionPoint) {
1414+
MachineBasicBlock *MBB = InsertionPoint->getParent();
1415+
MachineBasicBlock::iterator InsertPt =
1416+
std::next(InsertionPoint->getIterator());
1417+
if (InsertPt != MBB->end() && InsertPt->isPHI())
1418+
InsertPt = MBB->getFirstNonPHI();
1419+
B.setInsertPt(*MBB, *InsertPt);
1420+
}
1421+
14101422
/// Match a pattern of chained G_PTR_ADD operations where offsets come from
14111423
/// either G_TRUNC of s32 values or G_ZEXTLOAD of s16 values.
14121424
/// Combines them into a single PTR_ADD by adding the offsets in s32 space.
@@ -1493,15 +1505,9 @@ bool llvm::matchChainedPtrAddWithNonConstOffsets(MachineInstr &MI,
14931505

14941506
// Build the transformation
14951507
MatchInfo = [=, &MRI, &MI](MachineIRBuilder &B) {
1496-
// Set insertion point right after the dominated definition
1497-
// Be careful to not insert between phi nodes.
1498-
MachineBasicBlock *InsertPtMBB = InsertionPoint->getParent();
1499-
MachineBasicBlock::iterator InsertPt =
1500-
std::next(InsertionPoint->getIterator());
1501-
if (InsertPt != InsertPtMBB->end() && InsertPt->isPHI())
1502-
InsertPt = InsertPtMBB->getFirstNonPHI();
1503-
1504-
B.setInsertPt(*InsertPtMBB, *InsertPt);
1508+
// Set insertion point right after the dominated definition,
1509+
// skipping any PHI nodes that immediately follow it.
1510+
setInsertPtAfterInstr(B, InsertionPoint);
15051511

15061512
// Extend a register to S32 if it is currently S20 (from ZEXTLOAD).
15071513
auto ExtendToS32 = [&](Register Reg) -> Register {
@@ -1632,15 +1638,9 @@ bool llvm::matchPostIncLoadStorePtrAddWithTrunc(MachineInstr &MI,
16321638

16331639
// Build the lambda that will perform the transformation
16341640
MatchInfo = [=, &MRI, &MI, &Observer](MachineIRBuilder &B) {
1635-
// Set insertion point right after the dominated definition
1636-
// Be careful to not insert between phi nodes.
1637-
MachineBasicBlock *InsertPtMBB = InsertionPoint->getParent();
1638-
MachineBasicBlock::iterator InsertPt =
1639-
std::next(InsertionPoint->getIterator());
1640-
if (InsertPt != InsertPtMBB->end() && InsertPt->isPHI())
1641-
InsertPt = InsertPtMBB->getFirstNonPHI();
1642-
1643-
B.setInsertPt(*InsertPtMBB, *InsertPt);
1641+
// Set insertion point right after the dominated definition,
1642+
// skipping any PHI nodes that immediately follow it.
1643+
setInsertPtAfterInstr(B, InsertionPoint);
16441644

16451645
// Build G_ADD of the two s32 values
16461646
const Register CombinedS32 = MRI.createGenericVirtualRegister(S32);

0 commit comments

Comments
 (0)