xref: /llvm-project/llvm/test/Transforms/FunctionSpecialization/remove-dead-recursive-function.ll (revision e15d72adac66790a78a51a3087b56b2bde6b778a)
1; RUN: opt -passes="ipsccp<func-spec>" -funcspec-min-function-size=3 -S < %s | FileCheck %s
2
3define i64 @main(i64 %x, i1 %flag) {
4entry:
5  br i1 %flag, label %plus, label %minus
6
7plus:
8  %tmp0 = call i64 @compute(i64 %x, ptr @plus)
9  br label %merge
10
11minus:
12  %tmp1 = call i64 @compute(i64 %x, ptr @minus)
13  br label %merge
14
15merge:
16  %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus]
17  ret i64 %tmp2
18}
19
20; CHECK-NOT: define internal i64 @compute(
21;
22; CHECK-LABEL: define internal i64 @compute.specialized.1(i64 %n, ptr %binop) {
23; CHECK:  [[TMP0:%.+]] = call i64 @plus(i64 %n)
24; CHECK:  [[TMP1:%.+]] = call i64 @compute.specialized.1(i64 [[TMP2:%.+]], ptr @plus)
25; CHECK:  add nsw i64 [[TMP1]], [[TMP0]]
26;
27; CHECK-LABEL: define internal i64 @compute.specialized.2(i64 %n, ptr %binop) {
28; CHECK:  [[TMP0:%.+]] = call i64 @minus(i64 %n)
29; CHECK:  [[TMP1:%.+]] = call i64 @compute.specialized.2(i64 [[TMP2:%.+]], ptr @minus)
30; CHECK:  add nsw i64 [[TMP1]], [[TMP0]]
31;
32define internal i64 @compute(i64 %n, ptr %binop) {
33entry:
34  %cmp = icmp sgt i64 %n, 0
35  br i1 %cmp, label %if.then, label %if.end
36
37if.then:
38  %call = call i64 %binop(i64 %n)
39  %sub = add nsw i64 %n, -1
40  %call1 = call i64 @compute(i64 %sub, ptr %binop)
41  %add2 = add nsw i64 %call1, %call
42  br label %if.end
43
44if.end:
45  %result.0 = phi i64 [ %add2, %if.then ], [ 0, %entry ]
46  ret i64 %result.0
47}
48
49define internal i64 @plus(i64 %x) {
50entry:
51  %tmp0 = add i64 %x, 1
52  ret i64 %tmp0
53}
54
55define internal i64 @minus(i64 %x) {
56entry:
57  %tmp0 = sub i64 %x, 1
58  ret i64 %tmp0
59}
60