Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,9 +2797,10 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
Attrs.addByValAttr(getTypes().ConvertTypeForMem(ParamType));

auto *Decl = ParamType->getAsRecordDecl();
if (CodeGenOpts.PassByValueIsNoAlias && Decl &&
Decl->getArgPassingRestrictions() ==
RecordArgPassingKind::CanPassInRegs)
if (Decl && ((CodeGenOpts.PassByValueIsNoAlias &&
Decl->getArgPassingRestrictions() ==
RecordArgPassingKind::CanPassInRegs) ||
(!AI.getIndirectByVal() && Context.getTypeDeclType(Decl).isTrivialType(Context))))
// When calling the function, the pointer passed in will be the only
// reference to the underlying object. Mark it accordingly.
Attrs.addAttribute(llvm::Attribute::NoAlias);
Expand Down
8 changes: 4 additions & 4 deletions clang/test/CodeGen/AArch64/byval-temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void example(void) {
// Then, memcpy `l` to the temporary stack space.
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)
// Finally, call using a pointer to the temporary stack space.
// CHECK-O0-NEXT: call void @pass_large(ptr noundef %[[byvaltemp]])
// CHECK-O0-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp]])
// Now, do the same for the second call, using the second temporary alloca.
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp1]], ptr align 8 %[[l]], i64 64, i1 false)
// CHECK-O0-NEXT: call void @pass_large(ptr noundef %[[byvaltemp1]])
// CHECK-O0-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp1]])
// CHECK-O0-NEXT: ret void
//
// At O3, we should have lifetime markers to help the optimizer re-use the temporary allocas.
Expand All @@ -58,15 +58,15 @@ void example(void) {
// Then, memcpy `l` to the temporary stack space.
// CHECK-O3-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)
// Finally, call using a pointer to the temporary stack space.
// CHECK-O3-NEXT: call void @pass_large(ptr noundef %[[byvaltemp]])
// CHECK-O3-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp]])
//
// The lifetime of the temporary used to pass a pointer to the struct ends here.
// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %[[byvaltemp]])
//
// Now, do the same for the second call, using the second temporary alloca.
// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(i64 64, ptr %[[byvaltemp1]])
// CHECK-O3-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp1]], ptr align 8 %[[l]], i64 64, i1 false)
// CHECK-O3-NEXT: call void @pass_large(ptr noundef %[[byvaltemp1]])
// CHECK-O3-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp1]])
// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %[[byvaltemp1]])
//
// Mark the end of the lifetime of `l`.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/atomic-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void test3(pointer_pair_t pair) {
}

// CHECK-LABEL:define{{.*}} void @test4(
// CHECK-SAME: ptr noundef [[QUAD:%.*]])
// CHECK-SAME: ptr noalias noundef [[QUAD:%.*]])
// CHECK: [[QUAD_INDIRECT_ADDR:%.*]] = alloca ptr, align 8
// CHECK-NEXT: [[TEMP:%.*]] = alloca [[QUAD_T:%.*]], align 8
// CHECK-NEXT: store ptr [[QUAD]], ptr [[QUAD_INDIRECT_ADDR]]
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/attr-noundef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Huge {
Huge ret_huge() { return {}; }
void pass_huge(Huge h) {}
// CHECK: [[DEF]] void @{{.*}}ret_huge{{.*}}(ptr dead_on_unwind noalias writable sret({{[^)]+}}) align 4 %
// CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(ptr noundef
// CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(ptr noalias noundef
} // namespace check_structs

//************ Passing unions by value
Expand Down
Loading