1 ; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s
4 define i32 @test1_constants(i32 %x) {
6 %cond = icmp ugt i32 %x, 0 ; <i1> [#uses=1]
7 br i1 %cond, label %return, label %body
10 %y = add i32 %x, 1 ; <i32> [#uses=1]
11 %recurse = call i32 @test1_constants(i32 %y) ; <i32> [#uses=0]
14 return: ; preds = %entry
18 ; CHECK-LABEL: define i32 @test1_constants(
20 ; CHECK: %ret.tr = phi i32 [ poison, %entry ], [ %current.ret.tr, %body ]
21 ; CHECK: %ret.known.tr = phi i1 [ false, %entry ], [ true, %body ]
24 ; CHECK: %current.ret.tr = select i1 %ret.known.tr, i32 %ret.tr, i32 0
27 ; CHECK: %current.ret.tr1 = select i1 %ret.known.tr, i32 %ret.tr, i32 1
28 ; CHECK: ret i32 %current.ret.tr1
30 define i32 @test2_non_constants(i32 %x) {
32 %cond = icmp ugt i32 %x, 0
33 br i1 %cond, label %return, label %body
37 %helper1 = call i32 @test2_helper()
38 %recurse = call i32 @test2_non_constants(i32 %y)
42 %helper2 = call i32 @test2_helper()
46 declare i32 @test2_helper()
48 ; CHECK-LABEL: define i32 @test2_non_constants(
50 ; CHECK: %ret.tr = phi i32 [ poison, %entry ], [ %current.ret.tr, %body ]
51 ; CHECK: %ret.known.tr = phi i1 [ false, %entry ], [ true, %body ]
54 ; CHECK: %current.ret.tr = select i1 %ret.known.tr, i32 %ret.tr, i32 %helper1
57 ; CHECK: %current.ret.tr1 = select i1 %ret.known.tr, i32 %ret.tr, i32 %helper2
58 ; CHECK: ret i32 %current.ret.tr1
60 define i32 @test3_mixed(i32 %x) {
62 switch i32 %x, label %default [
69 %helper1 = call i32 @test3_helper()
74 %recurse1 = call i32 @test3_mixed(i32 %y1)
79 %helper2 = call i32 @test3_helper()
80 %recurse2 = call i32 @test3_mixed(i32 %y2)
85 %recurse3 = call i32 @test3_mixed(i32 %y3)
89 %retval = phi i32 [ %recurse3, %default ], [ %helper2, %case2 ], [ 9, %case1 ], [ %helper1, %case0 ]
93 declare i32 @test3_helper()
95 ; CHECK-LABEL: define i32 @test3_mixed(
97 ; CHECK: %ret.tr = phi i32 [ poison, %entry ], [ %current.ret.tr, %case1 ], [ %current.ret.tr1, %case2 ], [ %ret.tr, %default ]
98 ; CHECK: %ret.known.tr = phi i1 [ false, %entry ], [ true, %case1 ], [ true, %case2 ], [ %ret.known.tr, %default ]
100 ; CHECK-NOT: %recurse
101 ; CHECK: %current.ret.tr = select i1 %ret.known.tr, i32 %ret.tr, i32 9
102 ; CHECK: br label %tailrecurse
104 ; CHECK-NOT: %recurse
105 ; CHECK: %current.ret.tr1 = select i1 %ret.known.tr, i32 %ret.tr, i32 %helper2
106 ; CHECK: br label %tailrecurse
108 ; CHECK-NOT: %recurse
109 ; CHECK: br label %tailrecurse
111 ; CHECK: %current.ret.tr2 = select i1 %ret.known.tr, i32 %ret.tr, i32 %helper1
112 ; CHECK: ret i32 %current.ret.tr2