From 0897caad3010cfbb291c894f7972fb031e04abdf Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 30 Oct 2018 23:58:41 +0000 Subject: [PATCH] [Win64] Handle passing i128 by value For arguments, pass it indirectly, since the ABI doc says pretty clearly that arguments larger than 8 bytes are passed indirectly. This makes va_list handling easier, anyway. When returning, GCC returns in XMM0, and we match them. Fixes PR39492. llvm-svn: 345676 --- clang/lib/CodeGen/TargetInfo.cpp | 43 ++++++++++++++++++++++++++++++---------- clang/test/CodeGen/win64-i128.c | 16 +++++++++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 clang/test/CodeGen/win64-i128.c diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 1d6514e..ba9eadb 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -3944,18 +3944,39 @@ ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, unsigned &FreeSSERegs, return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), Width)); } - // Bool type is always extended to the ABI, other builtin types are not - // extended. - const BuiltinType *BT = Ty->getAs(); - if (BT && BT->getKind() == BuiltinType::Bool) - return ABIArgInfo::getExtend(Ty); + if (const BuiltinType *BT = Ty->getAs()) { + switch (BT->getKind()) { + case BuiltinType::Bool: + // Bool type is always extended to the ABI, other builtin types are not + // extended. + return ABIArgInfo::getExtend(Ty); - // Mingw64 GCC uses the old 80 bit extended precision floating point unit. It - // passes them indirectly through memory. - if (IsMingw64 && BT && BT->getKind() == BuiltinType::LongDouble) { - const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat(); - if (LDF == &llvm::APFloat::x87DoubleExtended()) - return ABIArgInfo::getIndirect(Align, /*ByVal=*/false); + case BuiltinType::LongDouble: + // Mingw64 GCC uses the old 80 bit extended precision floating point + // unit. It passes them indirectly through memory. + if (IsMingw64) { + const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat(); + if (LDF == &llvm::APFloat::x87DoubleExtended()) + return ABIArgInfo::getIndirect(Align, /*ByVal=*/false); + break; + } + + case BuiltinType::Int128: + case BuiltinType::UInt128: + // If it's a parameter type, the normal ABI rule is that arguments larger + // than 8 bytes are passed indirectly. GCC follows it. We follow it too, + // even though it isn't particularly efficient. + if (!IsReturnType) + return ABIArgInfo::getIndirect(Align, /*ByVal=*/false); + + // Mingw64 GCC returns i128 in XMM0. Coerce to v2i64 to handle that. + // Clang matches them for compatibility. + return ABIArgInfo::getDirect( + llvm::VectorType::get(llvm::Type::getInt64Ty(getVMContext()), 2)); + + default: + break; + } } return ABIArgInfo::getDirect(); diff --git a/clang/test/CodeGen/win64-i128.c b/clang/test/CodeGen/win64-i128.c new file mode 100644 index 0000000..0514c48 --- /dev/null +++ b/clang/test/CodeGen/win64-i128.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s \ +// RUN: | FileCheck %s --check-prefix=GNU64 +// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s \ +// RUN: | FileCheck %s --check-prefix=MSC64 + +typedef int int128_t __attribute__((mode(TI))); + +int128_t foo() { return 0; } + +// GNU64: define dso_local <2 x i64> @foo() +// MSC64: define dso_local <2 x i64> @foo() + +int128_t bar(int128_t a, int128_t b) { return a * b; } + +// GNU64: define dso_local <2 x i64> @bar(i128*, i128*) +// MSC64: define dso_local <2 x i64> @bar(i128*, i128*) -- 2.7.4