1 ; RUN: opt < %s -tailcallelim -S | FileCheck %s
3 define i32 @test1_factorial(i32 %x) {
5 %tmp.1 = icmp sgt i32 %x, 0 ; <i1> [#uses=1]
6 br i1 %tmp.1, label %then, label %else
8 %tmp.6 = add i32 %x, -1 ; <i32> [#uses=1]
9 %tmp.4 = call i32 @test1_factorial( i32 %tmp.6 ) ; <i32> [#uses=1]
10 %tmp.7 = mul i32 %tmp.4, %x ; <i32> [#uses=1]
12 else: ; preds = %entry
16 ; CHECK: define i32 @test1_factorial
21 ; This is a more aggressive form of accumulator recursion insertion, which
22 ; requires noticing that X doesn't change as we perform the tailcall.
24 define i32 @test2_mul(i32 %x, i32 %y) {
26 %tmp.1 = icmp eq i32 %y, 0 ; <i1> [#uses=1]
27 br i1 %tmp.1, label %return, label %endif
28 endif: ; preds = %entry
29 %tmp.8 = add i32 %y, -1 ; <i32> [#uses=1]
30 %tmp.5 = call i32 @test2_mul( i32 %x, i32 %tmp.8 ) ; <i32> [#uses=1]
31 %tmp.9 = add i32 %tmp.5, %x ; <i32> [#uses=1]
33 return: ; preds = %entry
37 ; CHECK: define i32 @test2_mul
43 define i64 @test3_fib(i64 %n) nounwind readnone {
47 ; CHECK: %accumulator.tr = phi i64 [ %n, %entry ], [ %3, %bb1 ]
48 ; CHECK: %n.tr = phi i64 [ %n, %entry ], [ %2, %bb1 ]
49 switch i64 %n, label %bb1 [
50 ; CHECK: switch i64 %n.tr, label %bb1 [
58 ; CHECK: %0 = add i64 %n.tr, -1
59 %1 = tail call i64 @test3_fib(i64 %0) nounwind
60 ; CHECK: %1 = tail call i64 @test3_fib(i64 %0)
62 ; CHECK: %2 = add i64 %n.tr, -2
63 %3 = tail call i64 @test3_fib(i64 %2) nounwind
64 ; CHECK-NOT: tail call i64 @test3_fib
65 %4 = add nsw i64 %3, %1
66 ; CHECK: add nsw i64 %accumulator.tr, %1
68 ; CHECK: br label %tailrecurse
73 ; CHECK: ret i64 %accumulator.tr