|
| 1 | +// RUN: %clang_cc1 -emit-llvm -triple arm64-- -o - %s -O0 | FileCheck %s --check-prefix=CHECK-O0 |
| 2 | +// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns -triple arm64-- -o - %s -O3 | FileCheck %s --check-prefix=CHECK-O3 |
| 3 | + |
| 4 | +struct large { |
| 5 | + void* pointers[8]; |
| 6 | +}; |
| 7 | + |
| 8 | +void pass_large(struct large); |
| 9 | + |
| 10 | +// For arm64, we don't use byval to pass structs but instead we create |
| 11 | +// temporary allocas. |
| 12 | +// |
| 13 | +// Make sure we generate the appropriate lifetime markers for the temporary |
| 14 | +// allocas so that the optimizer can re-use stack slots if possible. |
| 15 | +void example() { |
| 16 | + struct large l = {0}; |
| 17 | + pass_large(l); |
| 18 | + pass_large(l); |
| 19 | +} |
| 20 | +// CHECK-O0-LABEL: define void @example( |
| 21 | +// The alloca for the struct on the stack. |
| 22 | +// CHECK-O0: %[[l:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 23 | +// The alloca for the temporary stack space that we use to pass the argument. |
| 24 | +// CHECK-O0-NEXT: %[[byvaltemp:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 25 | +// Another one to pass the argument to the second function call. |
| 26 | +// CHECK-O0-NEXT: %[[byvaltemp1:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 27 | +// First, memset `l` to 0. |
| 28 | +// CHECK-O0-NEXT: %[[bitcastl:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 29 | +// CHECK-O0-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %[[bitcastl]], i8 0, i64 64, i1 false) |
| 30 | +// Then, memcpy `l` to the temporary stack space. |
| 31 | +// CHECK-O0-NEXT: %[[src:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp]] to i8* |
| 32 | +// CHECK-O0-NEXT: %[[dst:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 33 | +// CHECK-O0-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[src]], i8* align 8 %[[dst]], i64 64, i1 false) |
| 34 | +// Finally, call using a pointer to the temporary stack space. |
| 35 | +// CHECK-O0-NEXT: call void @pass_large(%struct.large* %[[byvaltemp]]) |
| 36 | +// Now, do the same for the second call, using the second temporary alloca. |
| 37 | +// CHECK-O0-NEXT: %[[src:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp1]] to i8* |
| 38 | +// CHECK-O0-NEXT: %[[dst:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 39 | +// CHECK-O0-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[src]], i8* align 8 %[[dst]], i64 64, i1 false) |
| 40 | +// CHECK-O0-NEXT: call void @pass_large(%struct.large* %[[byvaltemp1]]) |
| 41 | +// CHECK-O0-NEXT: ret void |
| 42 | +// |
| 43 | +// At O3, we should have lifetime markers to help the optimizer re-use the temporary allocas. |
| 44 | +// |
| 45 | +// CHECK-O3-LABEL: define void @example( |
| 46 | +// The alloca for the struct on the stack. |
| 47 | +// CHECK-O3: %[[l:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 48 | +// The alloca for the temporary stack space that we use to pass the argument. |
| 49 | +// CHECK-O3-NEXT: %[[byvaltemp:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 50 | +// Another one to pass the argument to the second function call. |
| 51 | +// CHECK-O3-NEXT: %[[byvaltemp1:[0-9A-Za-z-]+]] = alloca %struct.large, align 8 |
| 52 | +// |
| 53 | +// Mark the start of the lifetime for `l` |
| 54 | +// CHECK-O3-NEXT: %[[bitcastl:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 55 | +// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0i8(i64 64, i8* %[[bitcastl]]) |
| 56 | +// |
| 57 | +// First, memset `l` to 0. |
| 58 | +// CHECK-O3-NEXT: %[[bitcastl:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 59 | +// CHECK-O3-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 %[[bitcastl]], i8 0, i64 64, i1 false) |
| 60 | +// |
| 61 | +// Lifetime of the first temporary starts here and ends right after the call. |
| 62 | +// CHECK-O3-NEXT: %[[bitcastbyvaltemp:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp]] to i8* |
| 63 | +// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0i8(i64 64, i8* %[[bitcastbyvaltemp]]) |
| 64 | +// |
| 65 | +// Then, memcpy `l` to the temporary stack space. |
| 66 | +// CHECK-O3-NEXT: %[[src:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp]] to i8* |
| 67 | +// CHECK-O3-NEXT: %[[dst:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 68 | +// CHECK-O3-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[src]], i8* align 8 %[[dst]], i64 64, i1 false) |
| 69 | +// Finally, call using a pointer to the temporary stack space. |
| 70 | +// CHECK-O3-NEXT: call void @pass_large(%struct.large* %[[byvaltemp]]) |
| 71 | +// |
| 72 | +// The lifetime of the temporary used to pass a pointer to the struct ends here. |
| 73 | +// CHECK-O3-NEXT: %[[bitcastbyvaltemp:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp]] to i8* |
| 74 | +// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0i8(i64 64, i8* %[[bitcastbyvaltemp]]) |
| 75 | +// |
| 76 | +// Now, do the same for the second call, using the second temporary alloca. |
| 77 | +// CHECK-O3-NEXT: %[[bitcastbyvaltemp:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp1]] to i8* |
| 78 | +// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0i8(i64 64, i8* %[[bitcastbyvaltemp]]) |
| 79 | +// CHECK-O3-NEXT: %[[src:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp1]] to i8* |
| 80 | +// CHECK-O3-NEXT: %[[dst:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[l]] to i8* |
| 81 | +// CHECK-O3-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[src]], i8* align 8 %[[dst]], i64 64, i1 false) |
| 82 | +// CHECK-O3-NEXT: call void @pass_large(%struct.large* %[[byvaltemp1]]) |
| 83 | +// CHECK-O3-NEXT: %[[bitcastbyvaltemp:[0-9A-Za-z-]+]] = bitcast %struct.large* %[[byvaltemp1]] to i8* |
| 84 | +// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0i8(i64 64, i8* %[[bitcastbyvaltemp]]) |
| 85 | +// |
| 86 | +// Mark the end of the lifetime of `l`. |
| 87 | +// CHECK-O3-NEXT: %[[bitcastl:[0-9A-Za-z-]+]] = bitcast %struct.large* %l to i8* |
| 88 | +// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0i8(i64 64, i8* %[[bitcastl]]) |
| 89 | +// CHECK-O3-NEXT: ret void |
0 commit comments