xref: /llvm-project/llvm/test/Transforms/TailCallElim/tre-noncapturing-alloca-calls.ll (revision 8dc14a3bc05e50e86d7b26ac141364eccbceb134)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s
3
4; IR for that test was generated from the following C++ source:
5;
6;int count;
7;__attribute__((noinline)) void globalIncrement(const int* param) { count += *param; }
8;
9;void test(int recurseCount)
10;{
11;    if (recurseCount == 0) return;
12;    int temp = 10;
13;    globalIncrement(&temp);
14;    test(recurseCount - 1);
15;}
16;
17
18@count = dso_local local_unnamed_addr global i32 0, align 4
19
20; Function Attrs: nofree noinline norecurse nounwind uwtable
21declare void @_Z15globalIncrementPKi(ptr nocapture readonly %param) #0
22
23; Test that TRE could be done for recursive tail routine containing
24; call to function receiving a pointer to local stack.
25
26; Function Attrs: nounwind uwtable
27define dso_local void @_Z4testi(i32 %recurseCount) local_unnamed_addr #1 {
28; CHECK-LABEL: @_Z4testi(
29; CHECK-NEXT:  entry:
30; CHECK-NEXT:    [[TEMP:%.*]] = alloca i32, align 4
31; CHECK-NEXT:    br label [[TAILRECURSE:%.*]]
32; CHECK:       tailrecurse:
33; CHECK-NEXT:    [[RECURSECOUNT_TR:%.*]] = phi i32 [ [[RECURSECOUNT:%.*]], [[ENTRY:%.*]] ], [ [[SUB:%.*]], [[IF_END:%.*]] ]
34; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[RECURSECOUNT_TR]], 0
35; CHECK-NEXT:    br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END]]
36; CHECK:       if.end:
37; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[TEMP]])
38; CHECK-NEXT:    store i32 10, ptr [[TEMP]], align 4
39; CHECK-NEXT:    call void @_Z15globalIncrementPKi(ptr nonnull [[TEMP]])
40; CHECK-NEXT:    [[SUB]] = add nsw i32 [[RECURSECOUNT_TR]], -1
41; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[TEMP]])
42; CHECK-NEXT:    br label [[TAILRECURSE]]
43; CHECK:       return:
44; CHECK-NEXT:    ret void
45;
46entry:
47  %temp = alloca i32, align 4
48  %cmp = icmp eq i32 %recurseCount, 0
49  br i1 %cmp, label %return, label %if.end
50
51if.end:                                           ; preds = %entry
52  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %temp) #6
53  store i32 10, ptr %temp, align 4
54  call void @_Z15globalIncrementPKi(ptr nonnull %temp)
55  %sub = add nsw i32 %recurseCount, -1
56  call void @_Z4testi(i32 %sub)
57  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %temp) #6
58  br label %return
59
60return:                                           ; preds = %entry, %if.end
61  ret void
62}
63
64; Function Attrs: argmemonly nounwind willreturn
65declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
66
67; Function Attrs: argmemonly nounwind willreturn
68declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
69
70attributes #0 = { nofree noinline norecurse nounwind uwtable }
71attributes #1 = { nounwind uwtable }
72attributes #2 = { argmemonly nounwind willreturn }
73