; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s ; IR for that test was generated from the following C++ source: ; ;int count; ;__attribute__((noinline)) void globalIncrement(const int* param) { count += *param; } ; ;void test(int recurseCount) ;{ ; if (recurseCount == 0) return; ; int temp = 10; ; globalIncrement(&temp); ; test(recurseCount - 1); ;} ; @count = dso_local local_unnamed_addr global i32 0, align 4 ; Function Attrs: nofree noinline norecurse nounwind uwtable declare void @_Z15globalIncrementPKi(i32* nocapture readonly %param) #0 ; Test that TRE could be done for recursive tail routine containing ; call to function receiving a pointer to local stack. ; Function Attrs: nounwind uwtable define dso_local void @_Z4testi(i32 %recurseCount) local_unnamed_addr #1 { ; CHECK-LABEL: @_Z4testi( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TEMP:%.*]] = alloca i32, align 4 ; CHECK-NEXT: br label [[TAILRECURSE:%.*]] ; CHECK: tailrecurse: ; CHECK-NEXT: [[RECURSECOUNT_TR:%.*]] = phi i32 [ [[RECURSECOUNT:%.*]], [[ENTRY:%.*]] ], [ [[SUB:%.*]], [[IF_END:%.*]] ] ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[RECURSECOUNT_TR]], 0 ; CHECK-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END]] ; CHECK: if.end: ; CHECK-NEXT: [[TMP0:%.*]] = bitcast i32* [[TEMP]] to i8* ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull [[TMP0]]) ; CHECK-NEXT: store i32 10, i32* [[TEMP]], align 4 ; CHECK-NEXT: call void @_Z15globalIncrementPKi(i32* nonnull [[TEMP]]) ; CHECK-NEXT: [[SUB]] = add nsw i32 [[RECURSECOUNT_TR]], -1 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull [[TMP0]]) ; CHECK-NEXT: br label [[TAILRECURSE]] ; CHECK: return: ; CHECK-NEXT: ret void ; entry: %temp = alloca i32, align 4 %cmp = icmp eq i32 %recurseCount, 0 br i1 %cmp, label %return, label %if.end if.end: ; preds = %entry %0 = bitcast i32* %temp to i8* call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #6 store i32 10, i32* %temp, align 4 call void @_Z15globalIncrementPKi(i32* nonnull %temp) %sub = add nsw i32 %recurseCount, -1 call void @_Z4testi(i32 %sub) call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #6 br label %return return: ; preds = %entry, %if.end ret void } ; Function Attrs: argmemonly nounwind willreturn declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2 ; Function Attrs: argmemonly nounwind willreturn declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2 attributes #0 = { nofree noinline norecurse nounwind uwtable } attributes #1 = { nounwind uwtable } attributes #2 = { argmemonly nounwind willreturn }