Index: include/clang/Basic/LangOptions.def =================================================================== --- include/clang/Basic/LangOptions.def +++ include/clang/Basic/LangOptions.def @@ -172,6 +172,7 @@ "default maximum alignment for types") VALUE_LANGOPT(AlignDouble , 1, 0, "Controls if doubles should be aligned to 8 bytes (x86 only)") VALUE_LANGOPT(LongDoubleSize , 32, 0, "width of long double") +LANGOPT(PPCIEEELongDouble , 1, 0, "use IEEE 754 quadruple-precision long double") COMPATIBLE_VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level") COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie") LANGOPT(ROPI , 1, 0, "Read-only position independence") Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2014,6 +2014,7 @@ def m64 : Flag<["-"], "m64">, Group, Flags<[DriverOption, CoreOption]>; def mx32 : Flag<["-"], "mx32">, Group, Flags<[DriverOption, CoreOption]>; def mabi_EQ : Joined<["-"], "mabi=">, Group; +def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">, Group, Flags<[CC1Option]>; def miamcu : Flag<["-"], "miamcu">, Group, Flags<[DriverOption, CoreOption]>, HelpText<"Use Intel MCU ABI">; def mno_iamcu : Flag<["-"], "mno-iamcu">, Group, Flags<[DriverOption, CoreOption]>; Index: lib/Basic/Targets/PPC.cpp =================================================================== --- lib/Basic/Targets/PPC.cpp +++ lib/Basic/Targets/PPC.cpp @@ -466,7 +466,9 @@ Opts.AltiVec = 1; TargetInfo::adjust(Opts); if (LongDoubleFormat != &llvm::APFloat::IEEEdouble()) - LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble(); + LongDoubleFormat = Opts.PPCIEEELongDouble + ? &llvm::APFloat::IEEEquad() + : &llvm::APFloat::PPCDoubleDouble(); } ArrayRef PPCTargetInfo::getTargetBuiltins() const { Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1808,12 +1808,27 @@ break; } - if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) - // The ppc64 linux abis are all "altivec" abis by default. Accept and ignore - // the option if given as we don't have backend support for any targets - // that don't use the altivec abi. - if (StringRef(A->getValue()) != "altivec") - ABIName = A->getValue(); + bool IEEELongDouble = false, SeenLongDouble = false, SeenOther = false; + for (Arg *A : Args.filtered_reverse(options::OPT_mabi_EQ, + options::OPT_mabi_EQ_ieeelongdouble)) { + if (A->getOption().matches(options::OPT_mabi_EQ_ieeelongdouble)) { + A->claim(); + if (!SeenLongDouble) + IEEELongDouble = true; + SeenLongDouble = true; + } else if (StringRef(A->getValue()) == "ibmlongdouble") { + SeenLongDouble = true; + } else if (StringRef(A->getValue()) != "altivec") { + // The ppc64 linux abis are all "altivec" abis by default. Accept and ignore + // the option if given as we don't have backend support for any targets + // that don't use the altivec abi. + if (!SeenOther) + ABIName = A->getValue(); + SeenOther = true; + } + } + if (IEEELongDouble) + CmdArgs.push_back("-mabi=ieeelongdouble"); ppc::FloatABI FloatABI = ppc::getPPCFloatABI(getToolChain().getDriver(), Args); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -2745,6 +2745,7 @@ Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128) ? 128 : Args.hasArg(OPT_mlong_double_64) ? 64 : 0; + Opts.PPCIEEELongDouble = Args.hasArg(OPT_mabi_EQ_ieeelongdouble); Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); Opts.ROPI = Args.hasArg(OPT_fropi); Opts.RWPI = Args.hasArg(OPT_frwpi); Index: test/CodeGen/ppc64-long-double.cpp =================================================================== --- test/CodeGen/ppc64-long-double.cpp +++ test/CodeGen/ppc64-long-double.cpp @@ -3,6 +3,14 @@ // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s -mlong-double-64 | \ // RUN: FileCheck --check-prefix=FP64 %s +// musl defaults to -mlong-double-64, so -mlong-double-128 is needed to make +// -mabi=ieeelongdouble effective. +// RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - %s -mlong-double-128 \ +// RUN: -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s +// RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s \ +// RUN: -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s + +// IBM extended double is the default. // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=IBM128 %s // RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - -mlong-double-128 %s | \ @@ -13,10 +21,13 @@ // FP64: @x = global double {{.*}}, align 8 // FP64: @size = global i32 8 +// FP128: @x = global fp128 {{.*}}, align 16 +// FP128: @size = global i32 16 // IBM128: @x = global ppc_fp128 {{.*}}, align 16 // IBM128: @size = global i32 16 long double foo(long double d) { return d; } // FP64: double @_Z3fooe(double %d) +// FP128: fp128 @_Z3fooU10__float128(fp128 %d) // IBM128: ppc_fp128 @_Z3foog(ppc_fp128 %d) Index: test/Driver/ppc-abi.c =================================================================== --- test/Driver/ppc-abi.c +++ test/Driver/ppc-abi.c @@ -66,4 +66,20 @@ // CHECK-ELFv2-PIC: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv2-PIC: "-target-abi" "elfv2" +// Check -mabi=ieeelongdouble is passed through but it does not change -target-abi. +// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ieeelongdouble -mabi=elfv1 -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s +// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv1 -mabi=ieeelongdouble -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s +// CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble" +// CHECK-ELFv1-IEEE: "-target-abi" "elfv1" + +// Check -mabi=ibmlongdouble is the default. +// RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s +// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s + +// CHECK-ELFv2-IBM128-NOT: "-mabi=ieeelongdouble" +// CHECK-ELFv2-IBM128: "-target-abi" "elfv2"