121 lines · c
1// RUN: %clang_cc1 -emit-llvm -triple arm64-- -fexperimental-max-bitint-width=1024 -o - %s -O0 | FileCheck %s --check-prefix=CHECK-O02// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns -fexperimental-max-bitint-width=1024 -triple arm64-- -o - %s -O3 | FileCheck %s --check-prefix=CHECK-O33 4struct large {5 void* pointers[8];6};7 8void pass_large(struct large);9void pass_large_BitInt(_BitInt(129));10 11// For arm64, we don't use byval to pass structs and _BitInt(>128) type, but instead we create12// temporary allocas.13//14// Make sure we generate the appropriate lifetime markers for the temporary15// allocas so that the optimizer can re-use stack slots if possible.16void example(void) {17 struct large l = {0};18 pass_large(l);19 pass_large(l);20}21// CHECK-O0-LABEL: define{{.*}} void @example(22// The alloca for the struct on the stack.23// CHECK-O0: %[[l:[0-9A-Za-z-]+]] = alloca %struct.large, align 824// The alloca for the temporary stack space that we use to pass the argument.25// CHECK-O0-NEXT: %[[byvaltemp:[0-9A-Za-z-]+]] = alloca %struct.large, align 826// Another one to pass the argument to the second function call.27// CHECK-O0-NEXT: %[[byvaltemp1:[0-9A-Za-z-]+]] = alloca %struct.large, align 828// First, memset `l` to 0.29// CHECK-O0-NEXT: call void @llvm.memset.p0.i64(ptr align 8 %[[l]], i8 0, i64 64, i1 false)30// Then, memcpy `l` to the temporary stack space.31// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)32// Finally, call using a pointer to the temporary stack space.33// CHECK-O0-NEXT: call void @pass_large(ptr dead_on_return noundef %[[byvaltemp]])34// Now, do the same for the second call, using the second temporary alloca.35// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp1]], ptr align 8 %[[l]], i64 64, i1 false)36// CHECK-O0-NEXT: call void @pass_large(ptr dead_on_return noundef %[[byvaltemp1]])37// CHECK-O0-NEXT: ret void38//39// At O3, we should have lifetime markers to help the optimizer re-use the temporary allocas.40//41// CHECK-O3-LABEL: define{{.*}} void @example(42// The alloca for the struct on the stack.43// CHECK-O3: %[[l:[0-9A-Za-z-]+]] = alloca %struct.large, align 844// The alloca for the temporary stack space that we use to pass the argument.45// CHECK-O3-NEXT: %[[byvaltemp:[0-9A-Za-z-]+]] = alloca %struct.large, align 846// Another one to pass the argument to the second function call.47// CHECK-O3-NEXT: %[[byvaltemp1:[0-9A-Za-z-]+]] = alloca %struct.large, align 848//49// Mark the start of the lifetime for `l`50// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr %[[l]])51//52// First, memset `l` to 0.53// CHECK-O3-NEXT: call void @llvm.memset.p0.i64(ptr align 8 %[[l]], i8 0, i64 64, i1 false)54//55// Lifetime of the first temporary starts here and ends right after the call.56// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr %[[byvaltemp]])57//58// Then, memcpy `l` to the temporary stack space.59// CHECK-O3-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)60// Finally, call using a pointer to the temporary stack space.61// CHECK-O3-NEXT: call void @pass_large(ptr dead_on_return noundef %[[byvaltemp]])62//63// The lifetime of the temporary used to pass a pointer to the struct ends here.64// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr %[[byvaltemp]])65//66// Now, do the same for the second call, using the second temporary alloca.67// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr %[[byvaltemp1]])68// CHECK-O3-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp1]], ptr align 8 %[[l]], i64 64, i1 false)69// CHECK-O3-NEXT: call void @pass_large(ptr dead_on_return noundef %[[byvaltemp1]])70// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr %[[byvaltemp1]])71//72// Mark the end of the lifetime of `l`.73// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr %l)74// CHECK-O3-NEXT: ret void75 76void example_BitInt(void) {77 _BitInt(129) l = {0};78 pass_large_BitInt(l);79 pass_large_BitInt(l);80}81// CHECK-O0-LABEL: define dso_local void @example_BitInt(82// CHECK-O0-NEXT: entry:83// CHECK-O0-NEXT: [[L:%.*]] = alloca i256, align 1684// CHECK-O0-NEXT: [[INDIRECT_ARG_TEMP:%.*]] = alloca i256, align 1685// CHECK-O0-NEXT: [[INDIRECT_ARG_TEMP1:%.*]] = alloca i256, align 1686// CHECK-O0-NEXT: store i256 0, ptr [[L]], align 1687// CHECK-O0-NEXT: [[TMP0:%.*]] = load i256, ptr [[L]], align 1688// CHECK-O0-NEXT: [[LOADEDV:%.*]] = trunc i256 [[TMP0]] to i12989// CHECK-O0-NEXT: [[STOREDV:%.*]] = sext i129 [[LOADEDV]] to i25690// CHECK-O0-NEXT: store i256 [[STOREDV]], ptr [[INDIRECT_ARG_TEMP]], align 1691// CHECK-O0-NEXT: call void @pass_large_BitInt(ptr dead_on_return noundef [[INDIRECT_ARG_TEMP]])92// CHECK-O0-NEXT: [[TMP1:%.*]] = load i256, ptr [[L]], align 1693// CHECK-O0-NEXT: [[LOADEDV1:%.*]] = trunc i256 [[TMP1]] to i12994// CHECK-O0-NEXT: [[STOREDV1:%.*]] = sext i129 [[LOADEDV1]] to i25695// CHECK-O0-NEXT: store i256 [[STOREDV1]], ptr [[INDIRECT_ARG_TEMP1]], align 1696// CHECK-O0-NEXT: call void @pass_large_BitInt(ptr dead_on_return noundef [[INDIRECT_ARG_TEMP1]])97// CHECK-O0-NEXT: ret void98//99// CHECK-O3-LABEL: define dso_local void @example_BitInt(100// CHECK-O3-NEXT: entry:101// CHECK-O3-NEXT: [[L:%.*]] = alloca i256, align 16102// CHECK-O3-NEXT: [[INDIRECT_ARG_TEMP:%.*]] = alloca i256, align 16103// CHECK-O3-NEXT: [[INDIRECT_ARG_TEMP1:%.*]] = alloca i256, align 16104// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr [[L]]) 105// CHECK-O3-NEXT: store i256 0, ptr [[L]], align 16, !tbaa [[TBAA6:![0-9]+]]106// CHECK-O3-NEXT: [[TMP0:%.*]] = load i256, ptr [[L]], align 16, !tbaa [[TBAA6]]107// CHECK-O3-NEXT: [[LOADEDV:%.*]] = trunc i256 [[TMP0]] to i129108// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr [[INDIRECT_ARG_TEMP]]) 109// CHECK-O3-NEXT: [[STOREDV:%.*]] = sext i129 [[LOADEDV]] to i256110// CHECK-O3-NEXT: store i256 [[STOREDV]], ptr [[INDIRECT_ARG_TEMP]], align 16, !tbaa [[TBAA6]]111// CHECK-O3-NEXT: call void @pass_large_BitInt(ptr dead_on_return noundef [[INDIRECT_ARG_TEMP]])112// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr [[INDIRECT_ARG_TEMP]]) 113// CHECK-O3-NEXT: [[TMP1:%.*]] = load i256, ptr [[L]], align 16, !tbaa [[TBAA6]]114// CHECK-O3-NEXT: [[LOADEDV1:%.*]] = trunc i256 [[TMP1]] to i129115// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(ptr [[INDIRECT_ARG_TEMP1]]) 116// CHECK-O3-NEXT: [[STOREDV1:%.*]] = sext i129 [[LOADEDV1]] to i256117// CHECK-O3-NEXT: store i256 [[STOREDV1]], ptr [[INDIRECT_ARG_TEMP1]], align 16, !tbaa [[TBAA6]]118// CHECK-O3-NEXT: call void @pass_large_BitInt(ptr dead_on_return noundef [[INDIRECT_ARG_TEMP1]])119// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr [[INDIRECT_ARG_TEMP1]]) 120// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(ptr [[L]]) 121