blob: 4361c2e8bbf435b2aec3cfb8f28ec204606e90d1 [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
5
Tanya Lattner5640bd12008-03-01 09:15:35 +00006@A = weak global i32 0 ; <i32*> [#uses=1]
7@B = weak global i32 0 ; <i32*> [#uses=1]
8@C = weak global i32 0 ; <i32*> [#uses=1]
Chris Lattner73eedf02006-09-13 19:23:43 +00009
Tanya Lattner5640bd12008-03-01 09:15:35 +000010define internal fastcc void @foo(i32 %X) {
Chris Lattner73eedf02006-09-13 19:23:43 +000011entry:
Tanya Lattner5640bd12008-03-01 09:15:35 +000012 %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
13 %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
14 %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
15 br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
Chris Lattner73eedf02006-09-13 19:23:43 +000016
17cond_true: ; preds = %entry
Tanya Lattner5640bd12008-03-01 09:15:35 +000018 store i32 1, i32* @A
Chris Lattner73eedf02006-09-13 19:23:43 +000019 br label %cond_next
20
Tanya Lattner5640bd12008-03-01 09:15:35 +000021cond_next: ; preds = %cond_true, %entry
22 %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
23 %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
24 br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
Chris Lattner73eedf02006-09-13 19:23:43 +000025
26cond_true5: ; preds = %cond_next
Tanya Lattner5640bd12008-03-01 09:15:35 +000027 store i32 1, i32* @B
Chris Lattner73eedf02006-09-13 19:23:43 +000028 br label %cond_next7
29
Tanya Lattner5640bd12008-03-01 09:15:35 +000030cond_next7: ; preds = %cond_true5, %cond_next
31 %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
32 %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
33 br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
Chris Lattner73eedf02006-09-13 19:23:43 +000034
35cond_true11: ; preds = %cond_next7
Tanya Lattner5640bd12008-03-01 09:15:35 +000036 store i32 1, i32* @C
Chris Lattner73eedf02006-09-13 19:23:43 +000037 br label %cond_next13
38
Tanya Lattner5640bd12008-03-01 09:15:35 +000039cond_next13: ; preds = %cond_true11, %cond_next7
40 %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
41 %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
42 br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
Chris Lattner73eedf02006-09-13 19:23:43 +000043
44cond_true17: ; preds = %cond_next13
Tanya Lattner5640bd12008-03-01 09:15:35 +000045 call void @ext( i32* %ALL )
Chris Lattner73eedf02006-09-13 19:23:43 +000046 ret void
47
48UnifiedReturnBlock: ; preds = %cond_next13
49 ret void
50}
51
Tanya Lattner5640bd12008-03-01 09:15:35 +000052declare void @ext(i32*)
Chris Lattner73eedf02006-09-13 19:23:43 +000053
Tanya Lattner5640bd12008-03-01 09:15:35 +000054define void @test() {
Stephen Linc1c7a132013-07-14 01:42:54 +000055; CHECK-LABEL: @test(
Chandler Carruthbc3bc9d2012-03-24 21:24:19 +000056; CHECK-NOT: ret
57;
58; FIXME: This should be a CHECK-NOT, but currently we have a bug that causes us
59; to not nuke unused allocas.
60; CHECK: alloca
61; CHECK-NOT: ret
62;
63; No branches should survive the inliner's cleanup.
64; CHECK-NOT: br
65; CHECK: ret void
66
Chris Lattner73eedf02006-09-13 19:23:43 +000067entry:
Tanya Lattner5640bd12008-03-01 09:15:35 +000068 tail call fastcc void @foo( i32 1 )
69 tail call fastcc void @foo( i32 2 )
70 tail call fastcc void @foo( i32 3 )
71 tail call fastcc void @foo( i32 8 )
Chris Lattner73eedf02006-09-13 19:23:43 +000072 ret void
73}
Chandler Carruth21211992012-03-25 04:03:40 +000074
75declare void @f(i32 %x)
76
Chandler Carruthef82cf52012-03-25 10:34:54 +000077define void @inner2(i32 %x, i32 %y, i32 %z, i1 %b) {
Chandler Carruth21211992012-03-25 04:03:40 +000078entry:
79 %cmp1 = icmp ne i32 %x, 0
80 br i1 %cmp1, label %then1, label %end1
81
82then1:
83 call void @f(i32 %x)
84 br label %end1
85
86end1:
87 %x2 = and i32 %x, %z
88 %cmp2 = icmp sgt i32 %x2, 1
89 br i1 %cmp2, label %then2, label %end2
90
91then2:
92 call void @f(i32 %x2)
93 br label %end2
94
95end2:
96 %y2 = or i32 %y, %z
97 %cmp3 = icmp sgt i32 %y2, 0
98 br i1 %cmp3, label %then3, label %end3
99
100then3:
101 call void @f(i32 %y2)
102 br label %end3
103
104end3:
Chandler Carruthef82cf52012-03-25 10:34:54 +0000105 br i1 %b, label %end3.1, label %end3.2
106
107end3.1:
108 %x3.1 = or i32 %x, 10
109 br label %end3.3
110
111end3.2:
112 %x3.2 = or i32 %x, 10
113 br label %end3.3
114
115end3.3:
116 %x3.3 = phi i32 [ %x3.1, %end3.1 ], [ %x3.2, %end3.2 ]
117 %cmp4 = icmp slt i32 %x3.3, 1
118 br i1 %cmp4, label %then4, label %end4
119
120then4:
121 call void @f(i32 %x3.3)
122 br label %end4
123
124end4:
Chandler Carruth21211992012-03-25 04:03:40 +0000125 ret void
126}
127
Chandler Carruthef82cf52012-03-25 10:34:54 +0000128define void @outer2(i32 %z, i1 %b) {
Chandler Carruth21211992012-03-25 04:03:40 +0000129; Ensure that after inlining, none of the blocks with a call to @f actually
130; make it through inlining.
Stephen Lina76289a2013-07-14 01:50:49 +0000131; CHECK-LABEL: define void @outer2(
Chandler Carruth21211992012-03-25 04:03:40 +0000132; CHECK-NOT: call
133; CHECK: ret void
134
135entry:
Chandler Carruthef82cf52012-03-25 10:34:54 +0000136 call void @inner2(i32 0, i32 -1, i32 %z, i1 %b)
Chandler Carruth21211992012-03-25 04:03:40 +0000137 ret void
138}
Chandler Carruthe41f6f42012-04-06 01:11:52 +0000139
140define void @PR12470_inner(i16 signext %p1) nounwind uwtable {
141entry:
142 br i1 undef, label %cond.true, label %cond.false
143
144cond.true:
145 br label %cond.end
146
147cond.false:
148 %conv = sext i16 %p1 to i32
149 br label %cond.end
150
151cond.end:
152 %cond = phi i32 [ undef, %cond.true ], [ 0, %cond.false ]
153 %tobool = icmp eq i32 %cond, 0
154 br i1 %tobool, label %if.end5, label %if.then
155
156if.then:
157 ret void
158
159if.end5:
160 ret void
161}
162
163define void @PR12470_outer() {
164; This previously crashed during inliner cleanup and folding inner return
165; instructions. Check that we don't crash and we produce a function with a single
Chandler Carruth17e33582012-04-06 01:19:38 +0000166; return instruction due to merging the returns of the inlined function.
Stephen Lina76289a2013-07-14 01:50:49 +0000167; CHECK-LABEL: define void @PR12470_outer(
Chandler Carruthe547fef2012-04-06 17:21:28 +0000168; CHECK-NOT: call
Chandler Carruthe41f6f42012-04-06 01:11:52 +0000169; CHECK: ret void
170; CHECK-NOT: ret void
171; CHECK: }
172
173entry:
174 call void @PR12470_inner(i16 signext 1)
175 ret void
176}
Chandler Carruth49da9332012-04-06 17:21:31 +0000177
178define void @crasher_inner() nounwind uwtable {
179entry:
180 br i1 false, label %for.end28, label %for.body6
181
182for.body6:
183 br i1 undef, label %for.body6, label %for.cond12.for.inc26_crit_edge
184
185for.cond12.for.inc26_crit_edge:
186 br label %for.body6.1
187
188for.end28:
189 ret void
190
191for.body6.1:
192 br i1 undef, label %for.body6.1, label %for.cond12.for.inc26_crit_edge.1
193
194for.cond12.for.inc26_crit_edge.1:
195 br label %for.body6.2
196
197for.body6.2:
198 br i1 undef, label %for.body6.2, label %for.cond12.for.inc26_crit_edge.2
199
200for.cond12.for.inc26_crit_edge.2:
201 br label %for.end28
202}
203
204define void @crasher_outer() {
Stephen Linc1c7a132013-07-14 01:42:54 +0000205; CHECK-LABEL: @crasher_outer(
Chandler Carruth49da9332012-04-06 17:21:31 +0000206; CHECK-NOT: call
207; CHECK: ret void
208; CHECK-NOT: ret
209; CHECK: }
210entry:
211 tail call void @crasher_inner()
212 ret void
213}