Skip to content

Commit fb1120b

Browse files
committed
[IRGen] Mark pointers as noalias when passing trivial types by value.
1 parent 04ab8a5 commit fb1120b

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,9 +2797,10 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
27972797
Attrs.addByValAttr(getTypes().ConvertTypeForMem(ParamType));
27982798

27992799
auto *Decl = ParamType->getAsRecordDecl();
2800-
if (CodeGenOpts.PassByValueIsNoAlias && Decl &&
2801-
Decl->getArgPassingRestrictions() ==
2802-
RecordArgPassingKind::CanPassInRegs)
2800+
if (Decl && ((CodeGenOpts.PassByValueIsNoAlias &&
2801+
Decl->getArgPassingRestrictions() ==
2802+
RecordArgPassingKind::CanPassInRegs) ||
2803+
(!AI.getIndirectByVal() && Context.getTypeDeclType(Decl).isTrivialType(Context))))
28032804
// When calling the function, the pointer passed in will be the only
28042805
// reference to the underlying object. Mark it accordingly.
28052806
Attrs.addAttribute(llvm::Attribute::NoAlias);

clang/test/CodeGen/AArch64/byval-temp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ void example(void) {
3030
// Then, memcpy `l` to the temporary stack space.
3131
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)
3232
// Finally, call using a pointer to the temporary stack space.
33-
// CHECK-O0-NEXT: call void @pass_large(ptr noundef %[[byvaltemp]])
33+
// CHECK-O0-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp]])
3434
// Now, do the same for the second call, using the second temporary alloca.
3535
// 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 noundef %[[byvaltemp1]])
36+
// CHECK-O0-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp1]])
3737
// CHECK-O0-NEXT: ret void
3838
//
3939
// At O3, we should have lifetime markers to help the optimizer re-use the temporary allocas.
@@ -58,15 +58,15 @@ void example(void) {
5858
// Then, memcpy `l` to the temporary stack space.
5959
// CHECK-O3-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[byvaltemp]], ptr align 8 %[[l]], i64 64, i1 false)
6060
// Finally, call using a pointer to the temporary stack space.
61-
// CHECK-O3-NEXT: call void @pass_large(ptr noundef %[[byvaltemp]])
61+
// CHECK-O3-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp]])
6262
//
6363
// The lifetime of the temporary used to pass a pointer to the struct ends here.
6464
// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %[[byvaltemp]])
6565
//
6666
// Now, do the same for the second call, using the second temporary alloca.
6767
// CHECK-O3-NEXT: call void @llvm.lifetime.start.p0(i64 64, ptr %[[byvaltemp1]])
6868
// 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 noundef %[[byvaltemp1]])
69+
// CHECK-O3-NEXT: call void @pass_large(ptr noalias noundef %[[byvaltemp1]])
7070
// CHECK-O3-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr %[[byvaltemp1]])
7171
//
7272
// Mark the end of the lifetime of `l`.

clang/test/CodeGen/atomic-arm64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void test3(pointer_pair_t pair) {
5757
}
5858

5959
// CHECK-LABEL:define{{.*}} void @test4(
60-
// CHECK-SAME: ptr noundef [[QUAD:%.*]])
60+
// CHECK-SAME: ptr noalias noundef [[QUAD:%.*]])
6161
// CHECK: [[QUAD_INDIRECT_ADDR:%.*]] = alloca ptr, align 8
6262
// CHECK-NEXT: [[TEMP:%.*]] = alloca [[QUAD_T:%.*]], align 8
6363
// CHECK-NEXT: store ptr [[QUAD]], ptr [[QUAD_INDIRECT_ADDR]]

clang/test/CodeGen/attr-noundef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct Huge {
3535
Huge ret_huge() { return {}; }
3636
void pass_huge(Huge h) {}
3737
// CHECK: [[DEF]] void @{{.*}}ret_huge{{.*}}(ptr dead_on_unwind noalias writable sret({{[^)]+}}) align 4 %
38-
// CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(ptr noundef
38+
// CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(ptr noalias noundef
3939
} // namespace check_structs
4040

4141
//************ Passing unions by value

0 commit comments

Comments
 (0)