1 ; RUN: opt < %s -tailcallelim -verify-dom-info -S | FileCheck %s
2 ; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s
4 define i32 @test1_factorial(i32 %x) {
6 %tmp.1 = icmp sgt i32 %x, 0 ; <i1> [#uses=1]
7 br i1 %tmp.1, label %then, label %else
9 %tmp.6 = add i32 %x, -1 ; <i32> [#uses=1]
10 %tmp.4 = call i32 @test1_factorial( i32 %tmp.6 ) ; <i32> [#uses=1]
11 %tmp.7 = mul i32 %tmp.4, %x ; <i32> [#uses=1]
13 else: ; preds = %entry
17 ; CHECK-LABEL: define i32 @test1_factorial(
22 ; This is a more aggressive form of accumulator recursion insertion, which
23 ; requires noticing that X doesn't change as we perform the tailcall.
25 define i32 @test2_mul(i32 %x, i32 %y) {
27 %tmp.1 = icmp eq i32 %y, 0 ; <i1> [#uses=1]
28 br i1 %tmp.1, label %return, label %endif
29 endif: ; preds = %entry
30 %tmp.8 = add i32 %y, -1 ; <i32> [#uses=1]
31 %tmp.5 = call i32 @test2_mul( i32 %x, i32 %tmp.8 ) ; <i32> [#uses=1]
32 %tmp.9 = add i32 %tmp.5, %x ; <i32> [#uses=1]
34 return: ; preds = %entry
38 ; CHECK-LABEL: define i32 @test2_mul(
44 define i64 @test3_fib(i64 %n) nounwind readnone {
45 ; CHECK-LABEL: @test3_fib(
48 ; CHECK: %accumulator.tr = phi i64 [ %n, %entry ], [ %3, %bb1 ]
49 ; CHECK: %n.tr = phi i64 [ %n, %entry ], [ %2, %bb1 ]
50 switch i64 %n, label %bb1 [
51 ; CHECK: switch i64 %n.tr, label %bb1 [
59 ; CHECK: %0 = add i64 %n.tr, -1
60 %1 = tail call i64 @test3_fib(i64 %0) nounwind
61 ; CHECK: %1 = tail call i64 @test3_fib(i64 %0)
63 ; CHECK: %2 = add i64 %n.tr, -2
64 %3 = tail call i64 @test3_fib(i64 %2) nounwind
65 ; CHECK-NOT: tail call i64 @test3_fib
66 %4 = add nsw i64 %3, %1
67 ; CHECK: add nsw i64 %accumulator.tr, %1
69 ; CHECK: br label %tailrecurse
74 ; CHECK: ret i64 %accumulator.tr