blob: b744ae1ef396cd7dc7f8a8c3e996cd8713ae18cc [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() {
Chandler Carruthbc3bc9d2012-03-24 21:24:19 +000055; CHECK: @test
56; 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}