llvm.org GIT mirror llvm / da65822
Make tail merging handle blocks with repeated predecessors correctly, and remove RemoveDuplicateSuccessor, as it is no longer necessary, and because it breaks assumptions made in MachineBasicBlock::isOnlyReachableByFallthrough. Convert test/CodeGen/X86/omit-label.ll to FileCheck and add a testcase for PR4732. test/CodeGen/Thumb2/thumb2-ifcvt2.ll sees a diff with this commit due to it being bugpoint-reduced to the point where it doesn't matter what the condition for the branch is. Add some more interesting code to test/CodeGen/X86/2009-08-06-branchfolder-crash.ll, which is the testcase that originally motivated the RemoveDuplicateSuccessor code, to help verify that the original problem isn't being re-broken. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79338 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
4 changed file(s) with 93 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
699699
700700 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
701701 if (I->pred_size() >= 2 && I->pred_size() < TailMergeThreshold) {
702 SmallPtrSet UniquePreds;
702703 MachineBasicBlock *IBB = I;
703704 MachineBasicBlock *PredBB = prior(I);
704705 MergePotentials.clear();
708709 MachineBasicBlock* PBB = *P;
709710 // Skip blocks that loop to themselves, can't tail merge these.
710711 if (PBB==IBB)
712 continue;
713 // Visit each predecessor only once.
714 if (!UniquePreds.insert(PBB))
711715 continue;
712716 MachineBasicBlock *TBB = 0, *FBB = 0;
713717 SmallVector Cond;
849853 return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond);
850854 }
851855
852 /// RemoveDuplicateSuccessor - make sure block Pred has at most one
853 /// successor edge leading to Succ. This is only called in one place,
854 /// but Chris prefers that it be a separate function.
855 static void RemoveDuplicateSuccessor(MachineBasicBlock *Pred,
856 MachineBasicBlock *Succ) {
857 MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
858 bool found = false;
859 while (SI != Pred->succ_end()) {
860 if (*SI == Succ) {
861 if (!found) {
862 found = true;
863 ++SI;
864 } else {
865 SI = Pred->removeSuccessor(SI);
866 }
867 } else {
868 ++SI;
869 }
870 }
871 }
872
873856 /// IsBetterFallthrough - Return true if it would be clearly better to
874857 /// fall-through to MBB1 than to fall through into MBB2. This has to return
875858 /// a strict ordering, returning true for both (MBB1,MBB2) and (MBB2,MBB1) will
913896 while (!MBB->pred_empty()) {
914897 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
915898 Pred->ReplaceUsesOfBlockWith(MBB, FallThrough);
916 // If this resulted in a predecessor with true and false edges
917 // both going to the fallthrough block, clean up;
918 // BranchFolding doesn't like this.
919 RemoveDuplicateSuccessor(Pred, FallThrough);
920899 }
921900 // If MBB was the target of a jump table, update jump tables to go to the
922901 // fallthrough instead.
8181 entry:
8282 ; CHECK: t2:
8383 ; CHECK: cmp r0, #0
84 ; CHECK: bne.n
84 ; CHECK: beq.n
8585 br i1 undef, label %bb.i.i3, label %growMapping.exit
8686
8787 bb.i.i3: ; preds = %entry
8787 }
8888
8989 declare i32 @safe()
90
91 define i32 @func_35(i8 signext %p_35) nounwind readonly {
92 entry:
93 %tobool = icmp eq i8 %p_35, 0 ; [#uses=1]
94 br i1 %tobool, label %lor.lhs.false, label %if.then
95
96 lor.lhs.false: ; preds = %entry
97 %tmp1 = load i8* @g_3 ; [#uses=1]
98 %tobool3 = icmp eq i8 %tmp1, 0 ; [#uses=1]
99 br i1 %tobool3, label %return, label %if.then
100
101 if.then: ; preds = %lor.lhs.false, %entry
102 %tmp4 = load i8* @g_3 ; [#uses=1]
103 %conv5 = sext i8 %tmp4 to i32 ; [#uses=1]
104 ret i32 %conv5
105
106 return: ; preds = %lor.lhs.false
107 ret i32 0
108 }
109
110 define void @bar(i32 %p_5) noreturn nounwind {
111 entry:
112 %cmp = icmp sgt i32 %p_5, 0 ; [#uses=2]
113 %call = tail call i32 @safe() nounwind ; [#uses=1]
114 %conv1 = trunc i32 %call to i8 ; [#uses=3]
115 %tobool.i = xor i1 %cmp, true ; [#uses=3]
116 %cmp.i = icmp sgt i8 %conv1, 0 ; [#uses=3]
117 %or.cond.i = or i1 %cmp.i, %tobool.i ; [#uses=1]
118 br i1 %or.cond.i, label %lor.rhs.i, label %land.lhs.true3.i
119
120 land.lhs.true3.i: ; preds = %entry
121 %xor = zext i1 %cmp to i32 ; [#uses=1]
122 %conv5.i = sext i8 %conv1 to i32 ; [#uses=1]
123 %cmp7.i = icmp slt i32 %conv5.i, %xor ; [#uses=1]
124 %cmp7.i.not = xor i1 %cmp7.i, true ; [#uses=1]
125 %or.cond23.i = and i1 %cmp.i, %tobool.i ; [#uses=1]
126 %or.cond = and i1 %cmp7.i.not, %or.cond23.i ; [#uses=1]
127 br i1 %or.cond, label %lor.end.i, label %for.inc
128
129 lor.rhs.i: ; preds = %entry
130 %or.cond23.i.old = and i1 %cmp.i, %tobool.i ; [#uses=1]
131 br i1 %or.cond23.i.old, label %lor.end.i, label %for.inc
132
133 lor.end.i: ; preds = %lor.rhs.i, %land.lhs.true3.i
134 %tobool19.i = icmp eq i8 %conv1, 0 ; [#uses=0]
135 br label %for.inc
136
137 for.inc: ; preds = %for.inc, %lor.end.i, %lor.rhs.i, %land.lhs.true3.i
138 br label %for.inc
139 }
140
141 declare i32 @safe()
None ; RUN: llvm-as < %s | llc -march=x86-64 | grep BB1_1:
0 ; RUN: llvm-as < %s | llc -march=x86-64 -asm-verbose=false | FileCheck %s
11 ; PR4126
2 ; PR4732
23
3 ; Don't omit this label's definition.
4 ; Don't omit these labels' definitions.
5
6 ; CHECK: bux:
7 ; CHECK: .LBB1_1:
48
59 define void @bux(i32 %p_53) nounwind optsize {
610 entry:
2024 }
2125
2226 declare i32 @baz(...)
27
28 ; Don't omit this label in the assembly output.
29 ; CHECK: int321:
30 ; CHECK: jne .LBB2_1
31 ; CHECK: jle .LBB2_1
32 ; CHECK: .LBB2_1:
33
34 define void @int321(i8 signext %p_103, i32 %uint8p_104) nounwind readnone {
35 entry:
36 %tobool = icmp eq i8 %p_103, 0 ; [#uses=1]
37 %cmp.i = icmp sgt i8 %p_103, 0 ; [#uses=1]
38 %or.cond = and i1 %tobool, %cmp.i ; [#uses=1]
39 br i1 %or.cond, label %land.end.i, label %for.cond.preheader
40
41 land.end.i: ; preds = %entry
42 %conv3.i = sext i8 %p_103 to i32 ; [#uses=1]
43 %div.i = sdiv i32 1, %conv3.i ; [#uses=1]
44 %tobool.i = icmp eq i32 %div.i, -2147483647 ; [#uses=0]
45 br label %for.cond.preheader
46
47 for.cond.preheader: ; preds = %land.end.i, %entry
48 %cmp = icmp sgt i8 %p_103, 1 ; [#uses=1]
49 br i1 %cmp, label %for.end.split, label %for.cond
50
51 for.cond: ; preds = %for.cond.preheader, %for.cond
52 br label %for.cond
53
54 for.end.split: ; preds = %for.cond.preheader
55 ret void
56 }