[TRE] Merged several tests into the the test basic.ll.
[oota-llvm.git] / test / Transforms / TailCallElim / basic.ll
1 ; RUN: opt < %s -tailcallelim -S | FileCheck %s
2
3 declare void @noarg()
4 declare void @use(i32*)
5
6 ; Trivial case. Mark @noarg with tail call.
7 define void @test0() {
8 ; CHECK: tail call void @noarg()
9         call void @noarg()
10         ret void
11 }
12
13 ; PR615. Make sure that we do not move the alloca so that it interferes with the tail call.
14 define i32 @test1() {
15 ; CHECK: i32 @test1()
16 ; CHECK-NEXT: alloca
17         %A = alloca i32         ; <i32*> [#uses=2]
18         store i32 5, i32* %A
19         call void @use(i32* %A)
20         %X = tail call i32 @test1()             ; <i32> [#uses=1]
21         ret i32 %X
22 }
23
24 ; This function contains intervening instructions which should be moved out of the way
25 define i32 @test2(i32 %X) {
26 ; CHECK: i32 @test2
27 ; CHECK-NOT: call
28 ; CHECK: ret i32
29 entry:
30         %tmp.1 = icmp eq i32 %X, 0              ; <i1> [#uses=1]
31         br i1 %tmp.1, label %then.0, label %endif.0
32 then.0:         ; preds = %entry
33         %tmp.4 = add i32 %X, 1          ; <i32> [#uses=1]
34         ret i32 %tmp.4
35 endif.0:                ; preds = %entry
36         %tmp.10 = add i32 %X, -1                ; <i32> [#uses=1]
37         %tmp.8 = call i32 @test2(i32 %tmp.10)           ; <i32> [#uses=1]
38         %DUMMY = add i32 %X, 1          ; <i32> [#uses=0]
39         ret i32 %tmp.8
40 }
41
42 ; Though this case seems to be fairly unlikely to occur in the wild, someone
43 ; plunked it into the demo script, so maybe they care about it.
44 define i32 @test3(i32 %c) {
45 ; CHECK: i32 @test3
46 ; CHECK-NOT: call
47 ; CHECK: ret i32 0
48 entry:
49         %tmp.1 = icmp eq i32 %c, 0              ; <i1> [#uses=1]
50         br i1 %tmp.1, label %return, label %else
51 else:           ; preds = %entry
52         %tmp.5 = add i32 %c, -1         ; <i32> [#uses=1]
53         %tmp.3 = call i32 @test3(i32 %tmp.5)            ; <i32> [#uses=0]
54         ret i32 0
55 return:         ; preds = %entry
56         ret i32 0
57 }
58