blob: 344d900c5a3aff974c00b425da51f394640d7d93 [file] [log] [blame]
Chris Lattner73eedf02006-09-13 19:23:43 +00001; Test that the inliner doesn't leave around dead allocas, and that it folds
2; uncond branches away after it is done specializing.
3
Chandler Carruthbc3bc9d2012-03-24 21:24:19 +00004; RUN: opt < %s -inline -S | FileCheck %s
Chandler Carruth625038d2016-12-27 07:18:43 +00005; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
Chandler Carruthbc3bc9d2012-03-24 21:24:19 +00006
Tanya Lattner5640bd12008-03-01 09:15:35 +00007@A = weak global i32 0 ; <i32*> [#uses=1]
8@B = weak global i32 0 ; <i32*> [#uses=1]
9@C = weak global i32 0 ; <i32*> [#uses=1]
Chris Lattner73eedf02006-09-13 19:23:43 +000010
Tanya Lattner5640bd12008-03-01 09:15:35 +000011define internal fastcc void @foo(i32 %X) {
Chris Lattner73eedf02006-09-13 19:23:43 +000012entry:
Tanya Lattner5640bd12008-03-01 09:15:35 +000013 %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
14 %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
15 %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
16 br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
Chris Lattner73eedf02006-09-13 19:23:43 +000017
18cond_true: ; preds = %entry
Tanya Lattner5640bd12008-03-01 09:15:35 +000019 store i32 1, i32* @A
Chris Lattner73eedf02006-09-13 19:23:43 +000020 br label %cond_next
21
Tanya Lattner5640bd12008-03-01 09:15:35 +000022cond_next: ; preds = %cond_true, %entry
23 %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
24 %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
25 br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
Chris Lattner73eedf02006-09-13 19:23:43 +000026
27cond_true5: ; preds = %cond_next
Tanya Lattner5640bd12008-03-01 09:15:35 +000028 store i32 1, i32* @B
Chris Lattner73eedf02006-09-13 19:23:43 +000029 br label %cond_next7
30
Tanya Lattner5640bd12008-03-01 09:15:35 +000031cond_next7: ; preds = %cond_true5, %cond_next
32 %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
33 %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
34 br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
Chris Lattner73eedf02006-09-13 19:23:43 +000035
36cond_true11: ; preds = %cond_next7
Tanya Lattner5640bd12008-03-01 09:15:35 +000037 store i32 1, i32* @C
Chris Lattner73eedf02006-09-13 19:23:43 +000038 br label %cond_next13
39
Tanya Lattner5640bd12008-03-01 09:15:35 +000040cond_next13: ; preds = %cond_true11, %cond_next7
41 %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
42 %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
43 br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
Chris Lattner73eedf02006-09-13 19:23:43 +000044
45cond_true17: ; preds = %cond_next13
Tanya Lattner5640bd12008-03-01 09:15:35 +000046 call void @ext( i32* %ALL )
Chris Lattner73eedf02006-09-13 19:23:43 +000047 ret void
48
49UnifiedReturnBlock: ; preds = %cond_next13
50 ret void
51}
52
Tanya Lattner5640bd12008-03-01 09:15:35 +000053declare void @ext(i32*)
Chris Lattner73eedf02006-09-13 19:23:43 +000054
Tanya Lattner5640bd12008-03-01 09:15:35 +000055define void @test() {
Stephen Linc1c7a132013-07-14 01:42:54 +000056; CHECK-LABEL: @test(
Chandler Carruthbc3bc9d2012-03-24 21:24:19 +000057; CHECK-NOT: ret
58;
59; FIXME: This should be a CHECK-NOT, but currently we have a bug that causes us
60; to not nuke unused allocas.
61; CHECK: alloca
62; CHECK-NOT: ret
63;
64; No branches should survive the inliner's cleanup.
65; CHECK-NOT: br
66; CHECK: ret void
67
Chris Lattner73eedf02006-09-13 19:23:43 +000068entry:
Tanya Lattner5640bd12008-03-01 09:15:35 +000069 tail call fastcc void @foo( i32 1 )
70 tail call fastcc void @foo( i32 2 )
71 tail call fastcc void @foo( i32 3 )
72 tail call fastcc void @foo( i32 8 )
Chris Lattner73eedf02006-09-13 19:23:43 +000073 ret void
74}
Chandler Carruth21211992012-03-25 04:03:40 +000075
76declare void @f(i32 %x)
77
Chandler Carruthef82cf52012-03-25 10:34:54 +000078define void @inner2(i32 %x, i32 %y, i32 %z, i1 %b) {
Chandler Carruth21211992012-03-25 04:03:40 +000079entry:
80 %cmp1 = icmp ne i32 %x, 0
81 br i1 %cmp1, label %then1, label %end1
82
83then1:
84 call void @f(i32 %x)
85 br label %end1
86
87end1:
88 %x2 = and i32 %x, %z
89 %cmp2 = icmp sgt i32 %x2, 1
90 br i1 %cmp2, label %then2, label %end2
91
92then2:
93 call void @f(i32 %x2)
94 br label %end2
95
96end2:
97 %y2 = or i32 %y, %z
98 %cmp3 = icmp sgt i32 %y2, 0
99 br i1 %cmp3, label %then3, label %end3
100
101then3:
102 call void @f(i32 %y2)
103 br label %end3
104
105end3:
Chandler Carruthef82cf52012-03-25 10:34:54 +0000106 br i1 %b, label %end3.1, label %end3.2
107
108end3.1:
109 %x3.1 = or i32 %x, 10
110 br label %end3.3
111
112end3.2:
113 %x3.2 = or i32 %x, 10
114 br label %end3.3
115
116end3.3:
117 %x3.3 = phi i32 [ %x3.1, %end3.1 ], [ %x3.2, %end3.2 ]
118 %cmp4 = icmp slt i32 %x3.3, 1
119 br i1 %cmp4, label %then4, label %end4
120
121then4:
122 call void @f(i32 %x3.3)
123 br label %end4
124
125end4:
Chandler Carruth21211992012-03-25 04:03:40 +0000126 ret void
127}
128
Chandler Carruthef82cf52012-03-25 10:34:54 +0000129define void @outer2(i32 %z, i1 %b) {
Chandler Carruth21211992012-03-25 04:03:40 +0000130; Ensure that after inlining, none of the blocks with a call to @f actually
131; make it through inlining.
Stephen Lina76289a2013-07-14 01:50:49 +0000132; CHECK-LABEL: define void @outer2(
Chandler Carruth21211992012-03-25 04:03:40 +0000133; CHECK-NOT: call
134; CHECK: ret void
135
136entry:
Chandler Carruthef82cf52012-03-25 10:34:54 +0000137 call void @inner2(i32 0, i32 -1, i32 %z, i1 %b)
Chandler Carruth21211992012-03-25 04:03:40 +0000138 ret void
139}
Chandler Carruthe41f6f42012-04-06 01:11:52 +0000140
141define void @PR12470_inner(i16 signext %p1) nounwind uwtable {
142entry:
143 br i1 undef, label %cond.true, label %cond.false
144
145cond.true:
146 br label %cond.end
147
148cond.false:
149 %conv = sext i16 %p1 to i32
150 br label %cond.end
151
152cond.end:
153 %cond = phi i32 [ undef, %cond.true ], [ 0, %cond.false ]
154 %tobool = icmp eq i32 %cond, 0
155 br i1 %tobool, label %if.end5, label %if.then
156
157if.then:
158 ret void
159
160if.end5:
161 ret void
162}
163
164define void @PR12470_outer() {
165; This previously crashed during inliner cleanup and folding inner return
166; instructions. Check that we don't crash and we produce a function with a single
Chandler Carruth17e33582012-04-06 01:19:38 +0000167; return instruction due to merging the returns of the inlined function.
Stephen Lina76289a2013-07-14 01:50:49 +0000168; CHECK-LABEL: define void @PR12470_outer(
Chandler Carruthe547fef2012-04-06 17:21:28 +0000169; CHECK-NOT: call
Chandler Carruthe41f6f42012-04-06 01:11:52 +0000170; CHECK: ret void
171; CHECK-NOT: ret void
172; CHECK: }
173
174entry:
175 call void @PR12470_inner(i16 signext 1)
176 ret void
177}
Chandler Carruth49da9332012-04-06 17:21:31 +0000178
179define void @crasher_inner() nounwind uwtable {
180entry:
181 br i1 false, label %for.end28, label %for.body6
182
183for.body6:
184 br i1 undef, label %for.body6, label %for.cond12.for.inc26_crit_edge
185
186for.cond12.for.inc26_crit_edge:
187 br label %for.body6.1
188
189for.end28:
190 ret void
191
192for.body6.1:
193 br i1 undef, label %for.body6.1, label %for.cond12.for.inc26_crit_edge.1
194
195for.cond12.for.inc26_crit_edge.1:
196 br label %for.body6.2
197
198for.body6.2:
199 br i1 undef, label %for.body6.2, label %for.cond12.for.inc26_crit_edge.2
200
201for.cond12.for.inc26_crit_edge.2:
202 br label %for.end28
203}
204
205define void @crasher_outer() {
Stephen Linc1c7a132013-07-14 01:42:54 +0000206; CHECK-LABEL: @crasher_outer(
Chandler Carruth49da9332012-04-06 17:21:31 +0000207; CHECK-NOT: call
208; CHECK: ret void
209; CHECK-NOT: ret
210; CHECK: }
211entry:
212 tail call void @crasher_inner()
213 ret void
214}