Skip to content

Commit ca7ea08

Browse files
committed
Revert "AMDGPU: Split block for si_end_cf"
This reverts commit 7a6ef30. We discovered some internal test failures, so reverting for now. Differential Revision: https://reviews.llvm.org/D61213 Change-Id: I2bf19b5c7f4b76295d469872be579ca3a2f5850c git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359363 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c811b40 commit ca7ea08

File tree

7 files changed

+73
-227
lines changed

7 files changed

+73
-227
lines changed

lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,6 @@ bool SIInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
12141214
MI.setDesc(get(AMDGPU::S_XOR_B64));
12151215
break;
12161216

1217-
case AMDGPU::S_OR_B64_term:
1218-
// This is only a terminator to get the correct spill code placement during
1219-
// register allocation.
1220-
MI.setDesc(get(AMDGPU::S_OR_B64));
1221-
break;
1222-
12231217
case AMDGPU::S_ANDN2_B64_term:
12241218
// This is only a terminator to get the correct spill code placement during
12251219
// register allocation.
@@ -1704,7 +1698,6 @@ bool SIInstrInfo::analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
17041698
case AMDGPU::SI_MASK_BRANCH:
17051699
case AMDGPU::S_MOV_B64_term:
17061700
case AMDGPU::S_XOR_B64_term:
1707-
case AMDGPU::S_OR_B64_term:
17081701
case AMDGPU::S_ANDN2_B64_term:
17091702
break;
17101703
case AMDGPU::SI_IF:

lib/Target/AMDGPU/SIInstructions.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI<
189189
}
190190

191191
def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>;
192-
def S_OR_B64_term : WrapTerminatorInst<S_OR_B64>;
193192
def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>;
194193
def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>;
195194

lib/Target/AMDGPU/SILowerControlFlow.cpp

Lines changed: 15 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#include "llvm/ADT/StringRef.h"
5656
#include "llvm/CodeGen/LiveIntervals.h"
5757
#include "llvm/CodeGen/MachineBasicBlock.h"
58-
#include "llvm/CodeGen/MachineDominators.h"
5958
#include "llvm/CodeGen/MachineFunction.h"
6059
#include "llvm/CodeGen/MachineFunctionPass.h"
6160
#include "llvm/CodeGen/MachineInstr.h"
@@ -80,11 +79,8 @@ class SILowerControlFlow : public MachineFunctionPass {
8079
private:
8180
const SIRegisterInfo *TRI = nullptr;
8281
const SIInstrInfo *TII = nullptr;
83-
MachineRegisterInfo *MRI = nullptr;
8482
LiveIntervals *LIS = nullptr;
85-
MachineDominatorTree *DT = nullptr;
86-
MachineLoopInfo *MLI = nullptr;
87-
83+
MachineRegisterInfo *MRI = nullptr;
8884

8985
void emitIf(MachineInstr &MI);
9086
void emitElse(MachineInstr &MI);
@@ -115,7 +111,7 @@ class SILowerControlFlow : public MachineFunctionPass {
115111
AU.addPreservedID(LiveVariablesID);
116112
AU.addPreservedID(MachineLoopInfoID);
117113
AU.addPreservedID(MachineDominatorsID);
118-
114+
AU.setPreservesCFG();
119115
MachineFunctionPass::getAnalysisUsage(AU);
120116
}
121117
};
@@ -392,99 +388,23 @@ void SILowerControlFlow::emitLoop(MachineInstr &MI) {
392388
MI.eraseFromParent();
393389
}
394390

395-
// Insert \p Inst (which modifies exec) at \p InsPt in \p MBB, such that \p MBB
396-
// is split as necessary to keep the exec modification in its own block.
397-
static MachineBasicBlock *insertInstWithExecFallthrough(MachineBasicBlock &MBB,
398-
MachineInstr &MI,
399-
MachineInstr *NewMI,
400-
MachineDominatorTree *DT,
401-
LiveIntervals *LIS,
402-
MachineLoopInfo *MLI) {
403-
assert(NewMI->isTerminator());
404-
405-
MachineBasicBlock::iterator InsPt = MI.getIterator();
406-
if (std::next(MI.getIterator()) == MBB.end()) {
407-
// Don't bother with a new block.
408-
MBB.insert(InsPt, NewMI);
409-
if (LIS)
410-
LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
411-
MI.eraseFromParent();
412-
return &MBB;
413-
}
414-
415-
MachineFunction *MF = MBB.getParent();
416-
MachineBasicBlock *SplitMBB
417-
= MF->CreateMachineBasicBlock(MBB.getBasicBlock());
418-
419-
MF->insert(++MachineFunction::iterator(MBB), SplitMBB);
420-
421-
// FIXME: This is working around a MachineDominatorTree API defect.
422-
//
423-
// If a previous pass split a critical edge, it may not have been applied to
424-
// the DomTree yet. applySplitCriticalEdges is lazily applied, and inspects
425-
// the CFG of the given block. Make sure to call a dominator tree method that
426-
// will flush this cache before touching the successors of the block.
427-
MachineDomTreeNode *NodeMBB = nullptr;
428-
if (DT)
429-
NodeMBB = DT->getNode(&MBB);
430-
431-
// Move everything to the new block, except the end_cf pseudo.
432-
SplitMBB->splice(SplitMBB->begin(), &MBB, MBB.begin(), MBB.end());
433-
434-
SplitMBB->transferSuccessorsAndUpdatePHIs(&MBB);
435-
MBB.addSuccessor(SplitMBB, BranchProbability::getOne());
436-
437-
MBB.insert(MBB.end(), NewMI);
438-
439-
if (DT) {
440-
std::vector<MachineDomTreeNode *> Children = NodeMBB->getChildren();
441-
DT->addNewBlock(SplitMBB, &MBB);
442-
443-
// Reparent all of the children to the new block body.
444-
auto *SplitNode = DT->getNode(SplitMBB);
445-
for (auto *Child : Children)
446-
DT->changeImmediateDominator(Child, SplitNode);
447-
}
448-
449-
if (MLI) {
450-
if (MachineLoop *Loop = MLI->getLoopFor(&MBB))
451-
Loop->addBasicBlockToLoop(SplitMBB, MLI->getBase());
452-
}
453-
454-
if (LIS) {
455-
LIS->insertMBBInMaps(SplitMBB);
456-
LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
457-
}
458-
459-
// All live-ins are forwarded.
460-
for (auto &LiveIn : MBB.liveins())
461-
SplitMBB->addLiveIn(LiveIn);
462-
463-
MI.eraseFromParent();
464-
return SplitMBB;
465-
}
466-
467391
void SILowerControlFlow::emitEndCf(MachineInstr &MI) {
468392
MachineBasicBlock &MBB = *MI.getParent();
469393
const DebugLoc &DL = MI.getDebugLoc();
470394

471395
MachineBasicBlock::iterator InsPt = MBB.begin();
396+
MachineInstr *NewMI =
397+
BuildMI(MBB, InsPt, DL, TII->get(AMDGPU::S_OR_B64), AMDGPU::EXEC)
398+
.addReg(AMDGPU::EXEC)
399+
.add(MI.getOperand(0));
472400

473-
// First, move the instruction. It's unnecessarily difficult to update
474-
// LiveIntervals when there's a change in control flow, so move the
475-
// instruction before changing the blocks.
476-
MBB.splice(InsPt, &MBB, MI.getIterator());
477401
if (LIS)
478-
LIS->handleMove(MI);
402+
LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
479403

480-
MachineFunction *MF = MBB.getParent();
404+
MI.eraseFromParent();
481405

482-
// Create instruction without inserting it yet.
483-
MachineInstr *NewMI
484-
= BuildMI(*MF, DL, TII->get(AMDGPU::S_OR_B64_term), AMDGPU::EXEC)
485-
.addReg(AMDGPU::EXEC)
486-
.add(MI.getOperand(0));
487-
insertInstWithExecFallthrough(MBB, MI, NewMI, DT, LIS, MLI);
406+
if (LIS)
407+
LIS->handleMove(*NewMI);
488408
}
489409

490410
// Returns replace operands for a logical operation, either single result
@@ -550,20 +470,17 @@ bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
550470

551471
// This doesn't actually need LiveIntervals, but we can preserve them.
552472
LIS = getAnalysisIfAvailable<LiveIntervals>();
553-
DT = getAnalysisIfAvailable<MachineDominatorTree>();
554-
MLI = getAnalysisIfAvailable<MachineLoopInfo>();
555-
556473
MRI = &MF.getRegInfo();
557474

558475
MachineFunction::iterator NextBB;
559476
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
560477
BI != BE; BI = NextBB) {
561478
NextBB = std::next(BI);
562-
MachineBasicBlock *MBB = &*BI;
479+
MachineBasicBlock &MBB = *BI;
563480

564481
MachineBasicBlock::iterator I, Next, Last;
565482

566-
for (I = MBB->begin(), Last = MBB->end(); I != MBB->end(); I = Next) {
483+
for (I = MBB.begin(), Last = MBB.end(); I != MBB.end(); I = Next) {
567484
Next = std::next(I);
568485
MachineInstr &MI = *I;
569486

@@ -584,24 +501,10 @@ bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
584501
emitLoop(MI);
585502
break;
586503

587-
case AMDGPU::SI_END_CF: {
588-
MachineInstr *NextMI = nullptr;
589-
590-
if (Next != MBB->end())
591-
NextMI = &*Next;
592-
504+
case AMDGPU::SI_END_CF:
593505
emitEndCf(MI);
594-
595-
if (NextMI) {
596-
MBB = NextMI->getParent();
597-
Next = NextMI->getIterator();
598-
Last = MBB->end();
599-
}
600-
601-
NextBB = std::next(MBB->getIterator());
602-
BE = MF.end();
603506
break;
604-
}
507+
605508
case AMDGPU::S_AND_B64:
606509
case AMDGPU::S_OR_B64:
607510
// Cleanup bit manipulations on exec mask
@@ -615,7 +518,7 @@ bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
615518
}
616519

617520
// Replay newly inserted code to combine masks
618-
Next = (Last == MBB->end()) ? MBB->begin() : Last;
521+
Next = (Last == MBB.end()) ? MBB.begin() : Last;
619522
}
620523
}
621524

lib/Target/AMDGPU/SIOptimizeExecMasking.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ static bool removeTerminatorBit(const SIInstrInfo &TII, MachineInstr &MI) {
149149
MI.setDesc(TII.get(AMDGPU::S_XOR_B64));
150150
return true;
151151
}
152-
case AMDGPU::S_OR_B64_term: {
153-
// This is only a terminator to get the correct spill code placement during
154-
// register allocation.
155-
MI.setDesc(TII.get(AMDGPU::S_OR_B64));
156-
return true;
157-
}
158152
case AMDGPU::S_ANDN2_B64_term: {
159153
// This is only a terminator to get the correct spill code placement during
160154
// register allocation.

lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ FunctionPass *llvm::createSIOptimizeExecMaskingPreRAPass() {
8383
}
8484

8585
static bool isEndCF(const MachineInstr& MI, const SIRegisterInfo* TRI) {
86-
return MI.getOpcode() == AMDGPU::S_OR_B64_term &&
86+
return MI.getOpcode() == AMDGPU::S_OR_B64 &&
8787
MI.modifiesRegister(AMDGPU::EXEC, TRI);
8888
}
8989

@@ -362,7 +362,7 @@ bool SIOptimizeExecMaskingPreRA::runOnMachineFunction(MachineFunction &MF) {
362362

363363
// Try to collapse adjacent endifs.
364364
auto E = MBB.end();
365-
auto Lead = MBB.getFirstTerminator();
365+
auto Lead = skipDebugInstructionsForward(MBB.begin(), E);
366366
if (MBB.succ_size() != 1 || Lead == E || !isEndCF(*Lead, TRI))
367367
continue;
368368

0 commit comments

Comments
 (0)