1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s
4 ; IR for that test was generated from the following C++ source:
7 ;__attribute__((noinline)) void globalIncrement(const int* param) { count += *param; }
9 ;void test(int recurseCount)
11 ; if (recurseCount == 0) return;
13 ; globalIncrement(&temp);
14 ; test(recurseCount - 1);
18 @count = dso_local local_unnamed_addr global i32 0, align 4
20 ; Function Attrs: nofree noinline norecurse nounwind uwtable
21 declare void @_Z15globalIncrementPKi(ptr nocapture readonly %param) #0
23 ; Test that TRE could be done for recursive tail routine containing
24 ; call to function receiving a pointer to local stack.
26 ; Function Attrs: nounwind uwtable
27 define dso_local void @_Z4testi(i32 %recurseCount) local_unnamed_addr #1 {
28 ; CHECK-LABEL: @_Z4testi(
30 ; CHECK-NEXT: [[TEMP:%.*]] = alloca i32, align 4
31 ; CHECK-NEXT: br label [[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]]
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]]
44 ; CHECK-NEXT: ret void
47 %temp = alloca i32, align 4
48 %cmp = icmp eq i32 %recurseCount, 0
49 br i1 %cmp, label %return, label %if.end
51 if.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
60 return: ; preds = %entry, %if.end
64 ; Function Attrs: argmemonly nounwind willreturn
65 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
67 ; Function Attrs: argmemonly nounwind willreturn
68 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
70 attributes #0 = { nofree noinline norecurse nounwind uwtable }
71 attributes #1 = { nounwind uwtable }
72 attributes #2 = { argmemonly nounwind willreturn }