llvm.org GIT mirror llvm / 6b896ce
Fixes PR 1200 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34359 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 13 years ago
4 changed file(s) with 104 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
430430 bool BranchFolder::OptimizeBranches(MachineFunction &MF) {
431431 MadeChange = false;
432432
433 // Make sure blocks are numbered in order
434 MF.RenumberBlocks();
435
433436 for (MachineFunction::iterator I = ++MF.begin(), E = MF.end(); I != E; ) {
434437 MachineBasicBlock *MBB = I++;
435438 OptimizeBlock(MBB);
848851 PriorTBB, PriorFBB, PriorCond)) {
849852 // Now we know that there was no fall-through into this block, check to
850853 // see if it has a fall-through into its successor.
851 if (!CanFallThrough(MBB, CurUnAnalyzable, CurTBB, CurFBB, CurCond)) {
852 // Check all the predecessors of this block. If one of them has no fall
853 // throughs, move this block right after it.
854 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
855 E = MBB->pred_end(); PI != E; ++PI) {
856 // Analyze the branch at the end of the pred.
857 MachineBasicBlock *PredBB = *PI;
858 MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough;
859 std::vector PredCond;
860 if (PredBB != MBB && !CanFallThrough(PredBB)) {
861 MBB->moveAfter(PredBB);
862 MadeChange = true;
863 return OptimizeBlock(MBB);
854 bool CurFallsThru = CanFallThrough(MBB, CurUnAnalyzable, CurTBB, CurFBB,
855 CurCond);
856
857 // Check all the predecessors of this block. If one of them has no fall
858 // throughs, move this block right after it.
859 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
860 E = MBB->pred_end(); PI != E; ++PI) {
861 // Analyze the branch at the end of the pred.
862 MachineBasicBlock *PredBB = *PI;
863 MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough;
864 if (PredBB != MBB && !CanFallThrough(PredBB)
865 && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
866 // If the current block doesn't fall through, just move it.
867 // If the current block can fall through and does not end with a
868 // conditional branch, we need to append an unconditional jump to
869 // the (current) next block. To avoid a possible compile-time
870 // infinite loop, move blocks only backward in this case.
871 if (CurFallsThru) {
872 MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB));
873 CurCond.clear();
874 TII->InsertBranch(*MBB, NextBB, 0, CurCond);
864875 }
865 }
876 MBB->moveAfter(PredBB);
877 MadeChange = true;
878 return OptimizeBlock(MBB);
879 }
880 }
866881
882 if (!CurFallsThru) {
867883 // Check all successors to see if we can move this block before it.
868884 for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
869885 E = MBB->succ_end(); SI != E; ++SI) {
0 ; RUN: llvm-as < %s | llc &&
1 ; RUN: llvm-as < %s | llc | grep jmp | wc -l | grep 0
2
3 ; ModuleID = 'bugpoint.test.bc'
4 target datalayout = "e-p:32:32"
5 target triple = "i686-apple-darwin8"
6 %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
7 %struct.Index_Map = type { i32, %struct.item_set** }
8 %struct.Item = type { [4 x i16], %struct.rule* }
9 %struct.__sFILEX = type opaque
10 %struct.__sbuf = type { i8*, i32 }
11 %struct.dimension = type { i16*, %struct.Index_Map, %struct.mapping*, i32, %struct.plankMap* }
12 %struct.item_set = type { i32, i32, %struct.operator*, [2 x %struct.item_set*], %struct.item_set*, i16*, %struct.Item*, %struct.Item* }
13 %struct.list = type { i8*, %struct.list* }
14 %struct.mapping = type { %struct.list**, i32, i32, i32, %struct.item_set** }
15 %struct.nonterminal = type { i8*, i32, i32, i32, %struct.plankMap*, %struct.rule* }
16 %struct.operator = type { i8*, i8, i32, i32, i32, i32, %struct.table* }
17 %struct.pattern = type { %struct.nonterminal*, %struct.operator*, [2 x %struct.nonterminal*] }
18 %struct.plank = type { i8*, %struct.list*, i32 }
19 %struct.plankMap = type { %struct.list*, i32, %struct.stateMap* }
20 %struct.rule = type { [4 x i16], i32, i32, i32, %struct.nonterminal*, %struct.pattern*, i8 }
21 %struct.stateMap = type { i8*, %struct.plank*, i32, i16* }
22 %struct.table = type { %struct.operator*, %struct.list*, i16*, [2 x %struct.dimension*], %struct.item_set** }
23 @outfile = external global %struct.FILE* ; <%struct.FILE**> [#uses=1]
24 @str1 = external global [11 x i8] ; <[11 x i8]*> [#uses=1]
25
26 implementation ; Functions:
27
28 declare i32 @fprintf(%struct.FILE*, i8*, ...)
29
30 define i16 @main_bb_2E_i9_2E_i_2E_i932_2E_ce(%struct.list* %l_addr.01.0.i2.i.i929, %struct.operator** %tmp66.i62.i.out) {
31 newFuncRoot:
32 br label %bb.i9.i.i932.ce
33
34 bb36.i.i.exitStub: ; preds = %bb.i9.i.i932.ce
35 store %struct.operator* %tmp66.i62.i, %struct.operator** %tmp66.i62.i.out
36 ret i16 0
37
38 bb.i14.i.exitStub: ; preds = %bb.i9.i.i932.ce
39 store %struct.operator* %tmp66.i62.i, %struct.operator** %tmp66.i62.i.out
40 ret i16 1
41
42 bb12.i.i935.exitStub: ; preds = %bb.i9.i.i932.ce
43 store %struct.operator* %tmp66.i62.i, %struct.operator** %tmp66.i62.i.out
44 ret i16 2
45
46 bb20.i.i937.exitStub: ; preds = %bb.i9.i.i932.ce
47 store %struct.operator* %tmp66.i62.i, %struct.operator** %tmp66.i62.i.out
48 ret i16 3
49
50 bb28.i.i938.exitStub: ; preds = %bb.i9.i.i932.ce
51 store %struct.operator* %tmp66.i62.i, %struct.operator** %tmp66.i62.i.out
52 ret i16 4
53
54 bb.i9.i.i932.ce: ; preds = %newFuncRoot
55 %tmp1.i3.i.i930 = getelementptr %struct.list* %l_addr.01.0.i2.i.i929, i32 0, i32 0 ; [#uses=1]
56 %tmp2.i4.i.i931 = load i8** %tmp1.i3.i.i930 ; [#uses=1]
57 %tmp66.i62.i = bitcast i8* %tmp2.i4.i.i931 to %struct.operator* ; <%struct.operator*> [#uses=7]
58 %tmp1.i6.i = getelementptr %struct.operator* %tmp66.i62.i, i32 0, i32 2 ; [#uses=1]
59 %tmp2.i7.i = load i32* %tmp1.i6.i ; [#uses=1]
60 %tmp3.i8.i = load %struct.FILE** @outfile ; <%struct.FILE*> [#uses=1]
61 %tmp5.i9.i = call i32 (%struct.FILE*, i8*, ...)* @fprintf( %struct.FILE* %tmp3.i8.i, i8* getelementptr ([11 x i8]* @str1, i32 0, i32 0), i32 %tmp2.i7.i ) ; [#uses=0]
62 %tmp7.i10.i = getelementptr %struct.operator* %tmp66.i62.i, i32 0, i32 5 ; [#uses=1]
63 %tmp8.i11.i = load i32* %tmp7.i10.i ; [#uses=1]
64 switch i32 %tmp8.i11.i, label %bb36.i.i.exitStub [
65 i32 -1, label %bb.i14.i.exitStub
66 i32 0, label %bb12.i.i935.exitStub
67 i32 1, label %bb20.i.i937.exitStub
68 i32 2, label %bb28.i.i938.exitStub
69 ]
70 }
0 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 &&
1 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | grep 'b LBB.*cond_next48.loopexit' | wc -l | grep 1
1 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=ppc32 | grep 'b LBB.*' | wc -l | grep 5
2 ;;; FIXME, 4 unconditional branches is minimal
23
34 target endian = big
45 target pointersize = 32
None ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | %prcontext je 1 | grep "BB1_4:"
0 ; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 | %prcontext je 1 | grep "BB1_1:"
11
22 %str = internal constant [14 x sbyte] c"Hello world!\0A\00" ; <[14 x sbyte]*> [#uses=1]
33 %str = internal constant [13 x sbyte] c"Blah world!\0A\00" ; <[13 x sbyte]*> [#uses=1]