From 93ae947df36133c7a26a0c7d325c0679916ed2ed Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 16 Sep 2010 20:42:00 +0000 Subject: [PATCH] IRgen/ABI/x86_32/Darwin: On Darwin, only structures with SSE vector types get passed with a non-default-stack-ABI-alignment (of 16). - This fixes the ABI convenient, but breaks codegen since we now have underaligned arguments. Marginal improvement overall though, and will be fixed in next commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114113 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetInfo.cpp | 35 ++++++++++- ...-arguments.c => x86_32-arguments-darwin.c} | 62 ++++++++++++++++--- 2 files changed, 87 insertions(+), 10 deletions(-) rename test/CodeGen/{x86_32-arguments.c => x86_32-arguments-darwin.c} (71%) diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 2ae88f3a4c..ab6f7c7dd0 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -552,6 +552,33 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy) const { ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); } +static bool isRecordWithSSEVectorType(ASTContext &Context, QualType Ty) { + const RecordType *RT = Ty->getAs(); + if (!RT) + return 0; + const RecordDecl *RD = RT->getDecl(); + + // If this is a C++ record, check the bases first. + if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), + e = CXXRD->bases_end(); i != e; ++i) + if (!isRecordWithSSEVectorType(Context, i->getType())) + return false; + + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); + i != e; ++i) { + QualType FT = i->getType(); + + if (FT->getAs() && Context.getTypeSize(Ty) == 128) + return true; + + if (isRecordWithSSEVectorType(Context, FT)) + return true; + } + + return false; +} + unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty) const { // On non-Darwin, the stack type alignment is always 4. if (!IsDarwinVectorABI) @@ -563,9 +590,11 @@ unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty) const { if (Align <= MinABIStackAlignInBytes) return MinABIStackAlignInBytes; - // Otherwise, if the type contains SSE or MMX vector types, then the alignment - // matches that of the struct. - return Align; + // Otherwise, if the type contains an SSE vector type, the alignment is 16. + if (isRecordWithSSEVectorType(getContext(), Ty)) + return 16; + + return MinABIStackAlignInBytes; } ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal) const { diff --git a/test/CodeGen/x86_32-arguments.c b/test/CodeGen/x86_32-arguments-darwin.c similarity index 71% rename from test/CodeGen/x86_32-arguments.c rename to test/CodeGen/x86_32-arguments-darwin.c index 75dfb82b32..531ae1df69 100644 --- a/test/CodeGen/x86_32-arguments.c +++ b/test/CodeGen/x86_32-arguments-darwin.c @@ -94,11 +94,11 @@ T16 f16(void) { while (1) {} } // 128-bits). // CHECK: i32 @f17() -// CHECK: void @f18(%2* sret %agg.result) -// CHECK: void @f19(%3* sret %agg.result) -// CHECK: void @f20(%4* sret %agg.result) -// CHECK: void @f21(%5* sret %agg.result) -// CHECK: void @f22(%6* sret %agg.result) +// CHECK: void @f18(%{{.*}}* sret %agg.result) +// CHECK: void @f19(%{{.*}}* sret %agg.result) +// CHECK: void @f20(%{{.*}}* sret %agg.result) +// CHECK: void @f21(%{{.*}}* sret %agg.result) +// CHECK: void @f22(%{{.*}}* sret %agg.result) struct { T11 a; } f17(void) { while (1) {} } struct { T12 a; } f18(void) { while (1) {} } struct { T13 a; } f19(void) { while (1) {} } @@ -202,13 +202,13 @@ void f50(struct s50 a0) { } struct s51 { vvbp f0; int f1; }; void f51(struct s51 a0) { } -// CHECK: define void @f52(%struct.s52* byval align 16 %x) +// CHECK: define void @f52(%struct.s52* byval %x) struct s52 { long double a; }; void f52(struct s52 x) {} -// CHECK: define void @f53(%struct.s53* byval align 32 %x) +// CHECK: define void @f53(%struct.s53* byval %x) struct __attribute__((aligned(32))) s53 { int x; int y; @@ -228,3 +228,51 @@ typedef int v4i32 __attribute__((__vector_size__(16))); // PR8029 v4i32 f55(v4i32 arg) { return arg+arg; } +// CHECK: define void @f56( +// CHECK: i8 signext %a0, %struct.s56_0* byval %a1, +// CHECK: <2 x i32> %a2, %struct.s56_1* byval %a3, +// CHECK: i64 %a4.coerce, %struct.s56_2* byval %a5, +// CHECK: <4 x i32> %a6, %struct.s39* byval align 16 %a7, +// CHECK: <2 x double> %a8, %struct.s56_4* byval align 16 %a9, +// CHECK: <8 x i32> %a10, %struct.s56_5* byval %a11, +// CHECK: <4 x double> %a12, %struct.s56_6* byval %a13) + +// CHECK: call void (i32, ...)* @f56_0(i32 1, +// CHECK: i32 %{{[^ ]*}}, %struct.s56_0* byval %{{[^ ]*}}, +// CHECK: <2 x i32> %{{[^ ]*}}, %struct.s56_1* byval %{{[^ ]*}}, +// CHECK: i64 %{{[^ ]*}}, %struct.s56_2* byval %{{[^ ]*}}, +// CHECK: <4 x i32> %{{[^ ]*}}, %struct.s39* byval align 16 %{{[^ ]*}}, +// CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval align 16 %{{[^ ]*}}, +// CHECK: <8 x i32> {{[^ ]*}}, %struct.s56_5* byval %{{[^ ]*}}, +// CHECK: <4 x double> {{[^ ]*}}, %struct.s56_6* byval %{{[^ ]*}}) +// CHECK: } +// +// [i386] clang misaligns long double in structures +// when passed byval +// clang misaligns parameters on stack +typedef int __attribute__((vector_size (8))) t56_v2i; +typedef double __attribute__((vector_size (8))) t56_v1d; +typedef int __attribute__((vector_size (16))) t56_v4i; +typedef double __attribute__((vector_size (16))) t56_v2d; +typedef int __attribute__((vector_size (32))) t56_v8i; +typedef double __attribute__((vector_size (32))) t56_v4d; + +struct s56_0 { char a; }; +struct s56_1 { t56_v2i a; }; +struct s56_2 { t56_v1d a; }; +struct s56_3 { t56_v4i a; }; +struct s56_4 { t56_v2d a; }; +struct s56_5 { t56_v8i a; }; +struct s56_6 { t56_v4d a; }; + +void f56(char a0, struct s56_0 a1, + t56_v2i a2, struct s56_1 a3, + t56_v1d a4, struct s56_2 a5, + t56_v4i a6, struct s56_3 a7, + t56_v2d a8, struct s56_4 a9, + t56_v8i a10, struct s56_5 a11, + t56_v4d a12, struct s56_6 a13) { + extern void f56_0(int x, ...); + f56_0(1, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13); +} -- 2.40.0