diff options
| -rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 12 | ||||
| -rw-r--r-- | clang/test/CodeGen/x86_64-arguments.c | 7 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/alloca-align.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/virtual-functions-incomplete-types.cpp | 2 |
4 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index e95b3b6e901..2f8dd6c32d6 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -1086,6 +1086,13 @@ ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty, if (Ty->isIntegralOrEnumerationType() || Ty->hasPointerRepresentation()) return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); + + // If this is a 32-bit structure that is passed as an int64, then it will be + // passed in the low 32-bits of a 64-bit GPR, which is the same as how an + // i32 is passed. Coerce to a i32 instead of a i64. + if (Context.getTypeSizeInChars(Ty).getQuantity() == 4) + CoerceTo = llvm::Type::getInt32Ty(CoerceTo->getContext()); + } else if (CoerceTo->isDoubleTy()) { assert(Ty.isCanonical() && "should always have a canonical type here"); assert(!Ty.hasQualifiers() && "should never have a qualified type here"); @@ -1094,6 +1101,11 @@ ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty, if (Ty == Context.FloatTy || Ty == Context.DoubleTy) return ABIArgInfo::getDirect(); + // If this is a 32-bit structure that is passed as a double, then it will be + // passed in the low 32-bits of the XMM register, which is the same as how a + // float is passed. Coerce to a float instead of a double. + if (Context.getTypeSizeInChars(Ty).getQuantity() == 4) + CoerceTo = llvm::Type::getFloatTy(CoerceTo->getContext()); } return ABIArgInfo::getCoerce(CoerceTo); diff --git a/clang/test/CodeGen/x86_64-arguments.c b/clang/test/CodeGen/x86_64-arguments.c index d182aa25d91..24223901088 100644 --- a/clang/test/CodeGen/x86_64-arguments.c +++ b/clang/test/CodeGen/x86_64-arguments.c @@ -92,9 +92,10 @@ void f16(float a, float b, float c, float d, float e, float f, float g, float h, void f17(float a, float b, float c, float d, float e, float f, float g, float h, long double X) {} -// Check for valid coercion. -// CHECK: [[f18_t1:%.*]] = trunc i64 {{.*}} to i32 -// CHECK: store i32 [[f18_t1]], i32* +// Check for valid coercion. The struct should be passed/returned as i32, not +// as i64 for better code quality. +// rdar://8135035 +// CHECK: define void @f18(i32 %a, i32) struct f18_s0 { int f0; }; void f18(int a, struct f18_s0 f18_arg1) { while (1) {} } diff --git a/clang/test/CodeGenCXX/alloca-align.cpp b/clang/test/CodeGenCXX/alloca-align.cpp index b70e366f4cf..99d6ab5845f 100644 --- a/clang/test/CodeGenCXX/alloca-align.cpp +++ b/clang/test/CodeGenCXX/alloca-align.cpp @@ -18,7 +18,7 @@ extern "C" void f1() { (void) (struct s0) { 0, 0, 0, 0 }; } -// CHECK: define i64 @f2 +// CHECK: define i32 @f2 // CHECK: alloca %struct.s1, align 2 struct s1 { short x; short y; }; extern "C" struct s1 f2(int a, struct s1 *x, struct s1 *y) { diff --git a/clang/test/CodeGenCXX/virtual-functions-incomplete-types.cpp b/clang/test/CodeGenCXX/virtual-functions-incomplete-types.cpp index 991c2bc7220..052a0192d66 100644 --- a/clang/test/CodeGenCXX/virtual-functions-incomplete-types.cpp +++ b/clang/test/CodeGenCXX/virtual-functions-incomplete-types.cpp @@ -9,7 +9,7 @@ struct B { void B::f() { } -// CHECK: define i64 @_ZN1D1gEv(%struct.B* %this) +// CHECK: define i32 @_ZN1D1gEv(%struct.B* %this) // CHECK: declare void @_ZN1B1gEv() struct C; |

