llvm.org GIT mirror llvm / 5999c34
[LoopSimplify] Improve a test for loop simplify minorly. NFC. I did some basic testing while looking for a bug in my recent change to loop simplify and even though it didn't find the bug it seems like a useful improvement anyways. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306256 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 2 years ago
1 changed file(s) with 151 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
None ; RUN: opt < %s -loop-simplify
1 ; RUN: opt < %s -passes=loop-simplify
0 ; RUN: opt < %s -S -loop-simplify | FileCheck %s
1 ; RUN: opt < %s -S -passes=loop-simplify | FileCheck %s
22
3 ; This function should get a preheader inserted before BB3, that is jumped
4 ; to by BB1 & BB2
3 ; This function should get a preheader inserted before bb3, that is jumped
4 ; to by bb1 & bb2
5 define void @test() {
6 ; CHECK-LABEL: define void @test(
7 entry:
8 br i1 true, label %bb1, label %bb2
9
10 bb1:
11 br label %bb3
12 ; CHECK: bb1:
13 ; CHECK-NEXT: br label %[[PH:.*]]
14
15 bb2:
16 br label %bb3
17 ; CHECK: bb2:
18 ; CHECK-NEXT: br label %[[PH]]
19
20 bb3:
21 br label %bb3
22 ; CHECK: [[PH]]:
23 ; CHECK-NEXT: br label %bb3
524 ;
6
7 define void @test() {
8 br i1 true, label %BB1, label %BB2
9 BB1: ; preds = %0
10 br label %BB3
11 BB2: ; preds = %0
12 br label %BB3
13 BB3: ; preds = %BB3, %BB2, %BB1
14 br label %BB3
25 ; CHECK: bb3:
26 ; CHECK-NEXT: br label %bb3
1527 }
1628
29 ; Test a case where we have multiple exit blocks as successors of a single loop
30 ; block that need to be made dedicated exit blocks. We also have multiple
31 ; exiting edges to one of the exit blocks that all should be rewritten.
32 define void @test_multiple_exits_from_single_block(i8 %a, i8* %b.ptr) {
33 ; CHECK-LABEL: define void @test_multiple_exits_from_single_block(
34 entry:
35 switch i8 %a, label %loop [
36 i8 0, label %exit.a
37 i8 1, label %exit.b
38 ]
39 ; CHECK: entry:
40 ; CHECK-NEXT: switch i8 %a, label %[[PH:.*]] [
41 ; CHECK-NEXT: i8 0, label %exit.a
42 ; CHECK-NEXT: i8 1, label %exit.b
43 ; CHECK-NEXT: ]
44
45 loop:
46 %b = load volatile i8, i8* %b.ptr
47 switch i8 %b, label %loop [
48 i8 0, label %exit.a
49 i8 1, label %exit.b
50 i8 2, label %loop
51 i8 3, label %exit.a
52 i8 4, label %loop
53 i8 5, label %exit.a
54 i8 6, label %loop
55 ]
56 ; CHECK: [[PH]]:
57 ; CHECK-NEXT: br label %loop
58 ;
59 ; CHECK: loop:
60 ; CHECK-NEXT: %[[B:.*]] = load volatile i8, i8* %b.ptr
61 ; CHECK-NEXT: switch i8 %[[B]], label %[[BACKEDGE:.*]] [
62 ; CHECK-NEXT: i8 0, label %[[LOOPEXIT_A:.*]]
63 ; CHECK-NEXT: i8 1, label %[[LOOPEXIT_B:.*]]
64 ; CHECK-NEXT: i8 2, label %[[BACKEDGE]]
65 ; CHECK-NEXT: i8 3, label %[[LOOPEXIT_A]]
66 ; CHECK-NEXT: i8 4, label %[[BACKEDGE]]
67 ; CHECK-NEXT: i8 5, label %[[LOOPEXIT_A]]
68 ; CHECK-NEXT: i8 6, label %[[BACKEDGE]]
69 ; CHECK-NEXT: ]
70 ;
71 ; CHECK: [[BACKEDGE]]:
72 ; CHECK-NEXT: br label %loop
73
74 exit.a:
75 ret void
76 ; CHECK: [[LOOPEXIT_A]]:
77 ; CHECK-NEXT: br label %exit.a
78 ;
79 ; CHECK: exit.a:
80 ; CHECK-NEXT: ret void
81
82 exit.b:
83 ret void
84 ; CHECK: [[LOOPEXIT_B]]:
85 ; CHECK-NEXT: br label %exit.b
86 ;
87 ; CHECK: exit.b:
88 ; CHECK-NEXT: ret void
89 }
90
91 ; Check that we leave already dedicated exits alone when forming dedicated exit
92 ; blocks.
93 define void @test_pre_existing_dedicated_exits(i1 %a, i1* %ptr) {
94 ; CHECK-LABEL: define void @test_pre_existing_dedicated_exits(
95 entry:
96 br i1 %a, label %loop.ph, label %non_dedicated_exit
97 ; CHECK: entry:
98 ; CHECK-NEXT: br i1 %a, label %loop.ph, label %non_dedicated_exit
99
100 loop.ph:
101 br label %loop.header
102 ; CHECK: loop.ph:
103 ; CHECK-NEXT: br label %loop.header
104
105 loop.header:
106 %c1 = load volatile i1, i1* %ptr
107 br i1 %c1, label %loop.body1, label %dedicated_exit1
108 ; CHECK: loop.header:
109 ; CHECK-NEXT: %[[C1:.*]] = load volatile i1, i1* %ptr
110 ; CHECK-NEXT: br i1 %[[C1]], label %loop.body1, label %dedicated_exit1
111
112 loop.body1:
113 %c2 = load volatile i1, i1* %ptr
114 br i1 %c2, label %loop.body2, label %non_dedicated_exit
115 ; CHECK: loop.body1:
116 ; CHECK-NEXT: %[[C2:.*]] = load volatile i1, i1* %ptr
117 ; CHECK-NEXT: br i1 %[[C2]], label %loop.body2, label %[[LOOPEXIT:.*]]
118
119 loop.body2:
120 %c3 = load volatile i1, i1* %ptr
121 br i1 %c3, label %loop.backedge, label %dedicated_exit2
122 ; CHECK: loop.body2:
123 ; CHECK-NEXT: %[[C3:.*]] = load volatile i1, i1* %ptr
124 ; CHECK-NEXT: br i1 %[[C3]], label %loop.backedge, label %dedicated_exit2
125
126 loop.backedge:
127 br label %loop.header
128 ; CHECK: loop.backedge:
129 ; CHECK-NEXT: br label %loop.header
130
131 dedicated_exit1:
132 ret void
133 ; Check that there isn't a split loop exit.
134 ; CHECK-NOT: br label %dedicated_exit1
135 ;
136 ; CHECK: dedicated_exit1:
137 ; CHECK-NEXT: ret void
138
139 dedicated_exit2:
140 ret void
141 ; Check that there isn't a split loop exit.
142 ; CHECK-NOT: br label %dedicated_exit2
143 ;
144 ; CHECK: dedicated_exit2:
145 ; CHECK-NEXT: ret void
146
147 non_dedicated_exit:
148 ret void
149 ; CHECK: [[LOOPEXIT]]:
150 ; CHECK-NEXT: br label %non_dedicated_exit
151 ;
152 ; CHECK: non_dedicated_exit:
153 ; CHECK-NEXT: ret void
154 }