Skip to content

Commit 734b863

Browse files
committed
Add unconditional-branch-to-next
1 parent 76b784d commit 734b863

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/Target/AMDGPU/SICustomBranchBundles.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ static inline void hoistUnrelatedCopies(MachineFunction &MF) {
231231
while (!CopyMoveIt.isEnd()) {
232232
EpilogIterator Next = CopyMoveIt;
233233
++Next;
234-
if (CopyMoveIt->getOpcode() == AMDGPU::COPY &&
235-
!RelatedCopySources.count(CopyMoveIt->getOperand(1).getReg()) ||
234+
if ((CopyMoveIt->getOpcode() == AMDGPU::COPY &&
235+
!RelatedCopySources.count(CopyMoveIt->getOperand(1).getReg())) ||
236236
CopyMoveIt->getOpcode() == AMDGPU::IMPLICIT_DEF) {
237237
MachineInstr &MIToMove = *CopyMoveIt;
238238
MIToMove.removeFromBundle();
@@ -243,3 +243,19 @@ static inline void hoistUnrelatedCopies(MachineFunction &MF) {
243243
}
244244
}
245245
}
246+
247+
static inline bool makeEverySuccessorBeBranchTarget(MachineFunction &MF) {
248+
bool Changed = false;
249+
auto &TII = *MF.getSubtarget<GCNSubtarget>().getInstrInfo();
250+
for (MachineBasicBlock &MBB : MF)
251+
if (MBB.empty() ||
252+
(!MBB.back().isUnconditionalBranch() && !MBB.back().isReturn())) {
253+
MachineBasicBlock *LayoutSuccessor =
254+
&*std::next(MachineFunction::iterator(MBB));
255+
BuildMI(&MBB, DebugLoc(), TII.get(AMDGPU::S_BRANCH))
256+
.addMBB(LayoutSuccessor);
257+
Changed = true;
258+
}
259+
260+
return Changed;
261+
}

llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ bool SILowerControlFlow::run(MachineFunction &MF) {
800800
}
801801
}
802802

803-
bool Changed = false;
803+
bool Changed = makeEverySuccessorBeBranchTarget(MF);
804804
MachineFunction::iterator NextBB;
805805
for (MachineFunction::iterator BI = MF.begin();
806806
BI != MF.end(); BI = NextBB) {

0 commit comments

Comments
 (0)