llvm.org GIT mirror llvm / 71e6bc5
[mips] Fix compact branch hazard detection, part 2 Follow up to D27209 fix, this patch now properly handles single transient instruction in basic block. Patch by Aleksandar Beserminji. Differential Revision: https://reviews.llvm.org/D27856 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290361 91177308-0d34-0410-b5e6-96231b3b80d8 Petar Jovanovic 2 years ago
2 changed file(s) with 49 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
102102
103103 // Find the next real instruction from the current position, looking through
104104 // basic block boundaries.
105 static Iter getNextMachineInstr(Iter Position) {
106 if (std::next(Position) == Position->getParent()->end()) {
107 const MachineBasicBlock * MBB = (&*Position)->getParent();
108 for (auto *Succ : MBB->successors()) {
109 if (MBB->isLayoutSuccessor(Succ)) {
110 Iter I = Succ->begin();
111 Iter Next = getNextMachineInstrInBB(I);
112 if (Next == Succ->end()) {
113 return getNextMachineInstr(I);
114 } else {
115 return I;
116 }
117 }
105 static Iter getNextMachineInstr(Iter Position, MachineBasicBlock *Parent) {
106 if (Position == Parent->end()) {
107 MachineBasicBlock *Succ = Parent->getNextNode();
108 if (Succ != nullptr && Parent->isSuccessor(Succ)) {
109 Position = Succ->begin();
110 Parent = Succ;
111 } else {
112 llvm_unreachable(
113 "Should have identified the end of the function earlier!");
118114 }
119 llvm_unreachable("Should have identified the end of the function earlier!");
120115 }
121116
122 return getNextMachineInstrInBB(Position);
117 Iter Instr = getNextMachineInstrInBB(Position);
118 if (Instr == Parent->end()) {
119 return getNextMachineInstr(Instr, Parent);
120 }
121 return Instr;
123122 }
124123
125124 bool MipsHazardSchedule::runOnMachineFunction(MachineFunction &MF) {
145144 bool LastInstInFunction =
146145 std::next(I) == FI->end() && std::next(FI) == MF.end();
147146 if (!LastInstInFunction) {
148 if (std::next(I) != FI->end()) {
149 // Start looking from the next instruction in the basic block.
150 Inst = getNextMachineInstr(std::next(I));
151 } else {
152 // Next instruction in the physical successor basic block.
153 Inst = getNextMachineInstr(I);
154 }
147 Inst = getNextMachineInstr(std::next(I), &*FI);
155148 }
156149
157150 if (LastInstInFunction || !TII->SafeInForbiddenSlot(*Inst)) {
0 ; RUN: llc -march=mips64el -O0 -mcpu=mips64r6 < %s | FileCheck %s
1 ; RUN: llc -march=mips64 -O0 -mcpu=mips64r6 < %s | FileCheck %s
2
3 @boo = global i32 0, align 4
4
5 ; Function Attrs: nounwind
6 define void @_Z3foov() #0 {
7 entry:
8 %0 = load volatile i32, i32* @boo, align 4
9 switch i32 %0, label %sw.epilog [
10 i32 0, label %sw.bb
11 i32 1, label %sw.bb1
12 i32 2, label %sw.bb1
13 ]
14
15 sw.bb: ; preds = %entry
16 store volatile i32 1, i32* @boo, align 4
17 br label %sw.epilog
18 ; CHECK: beqzc
19 ; CHECK-NEXT: nop
20 ; CHECK-NEXT: .LBB
21 ; CHECK-NEXT: j
22
23 sw.bb1: ; preds = %entry, %entry
24 store volatile i32 2, i32* @boo, align 4
25 br label %sw.epilog
26 ; CHECK: bnezc
27 ; CHECK-NEXT: nop
28 ; CHECK-NEXT: .LBB
29 ; CHECK-NEXT: j
30
31 sw.epilog: ; preds = %entry, %sw.bb1, %sw.bb
32 ret void
33 }