Author: hfinkel Date: Sat Oct 1 21:10:45 2016 New Revision: 283061 URL: http://llvm.org/viewvc/llvm-project?rev=283061&view=rev Log: [PowerPC] Enable soft-float for PPC64, and +soft-float -> -hard-float
Enable soft-float support on PPC64, as the backend now supports it. Also, the backend now uses -hard-float instead of +soft-float, so set the target features accordingly. Fixes PR26970. Added: cfe/trunk/test/CodeGen/ppc64-soft-float.c Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/ppc-features.cpp Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=283061&r1=283060&r2=283061&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Sat Oct 1 21:10:45 2016 @@ -3899,6 +3899,7 @@ private: static const unsigned GPRBits = 64; ABIKind Kind; bool HasQPX; + bool IsSoftFloatABI; // A vector of float or double will be promoted to <4 x f32> or <4 x f64> and // will be passed in a QPX register. @@ -3929,8 +3930,10 @@ private: } public: - PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind, bool HasQPX) - : ABIInfo(CGT), Kind(Kind), HasQPX(HasQPX) {} + PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind, bool HasQPX, + bool SoftFloatABI) + : ABIInfo(CGT), Kind(Kind), HasQPX(HasQPX), + IsSoftFloatABI(SoftFloatABI) {} bool isPromotableTypeForABI(QualType Ty) const; CharUnits getParamTypeAlignment(QualType Ty) const; @@ -3978,8 +3981,10 @@ class PPC64_SVR4_TargetCodeGenInfo : pub public: PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, - PPC64_SVR4_ABIInfo::ABIKind Kind, bool HasQPX) - : TargetCodeGenInfo(new PPC64_SVR4_ABIInfo(CGT, Kind, HasQPX)) {} + PPC64_SVR4_ABIInfo::ABIKind Kind, bool HasQPX, + bool SoftFloatABI) + : TargetCodeGenInfo(new PPC64_SVR4_ABIInfo(CGT, Kind, HasQPX, + SoftFloatABI)) {} int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override { // This is recovered from gcc output. @@ -4197,8 +4202,11 @@ bool PPC64_SVR4_ABIInfo::isHomogeneousAg if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) { if (BT->getKind() == BuiltinType::Float || BT->getKind() == BuiltinType::Double || - BT->getKind() == BuiltinType::LongDouble) + BT->getKind() == BuiltinType::LongDouble) { + if (IsSoftFloatABI) + return false; return true; + } } if (const VectorType *VT = Ty->getAs<VectorType>()) { if (getContext().getTypeSize(VT) == 128 || IsQPXVectorTy(Ty)) @@ -8107,8 +8115,10 @@ const TargetCodeGenInfo &CodeGenModule:: if (getTarget().getABI() == "elfv2") Kind = PPC64_SVR4_ABIInfo::ELFv2; bool HasQPX = getTarget().getABI() == "elfv1-qpx"; + bool IsSoftFloat = CodeGenOpts.FloatABI == "soft"; - return SetCGInfo(new PPC64_SVR4_TargetCodeGenInfo(Types, Kind, HasQPX)); + return SetCGInfo(new PPC64_SVR4_TargetCodeGenInfo(Types, Kind, HasQPX, + IsSoftFloat)); } else return SetCGInfo(new PPC64TargetCodeGenInfo(Types)); case llvm::Triple::ppc64le: { @@ -8117,8 +8127,10 @@ const TargetCodeGenInfo &CodeGenModule:: if (getTarget().getABI() == "elfv1" || getTarget().getABI() == "elfv1-qpx") Kind = PPC64_SVR4_ABIInfo::ELFv1; bool HasQPX = getTarget().getABI() == "elfv1-qpx"; + bool IsSoftFloat = CodeGenOpts.FloatABI == "soft"; - return SetCGInfo(new PPC64_SVR4_TargetCodeGenInfo(Types, Kind, HasQPX)); + return SetCGInfo(new PPC64_SVR4_TargetCodeGenInfo(Types, Kind, HasQPX, + IsSoftFloat)); } case llvm::Triple::nvptx: Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=283061&r1=283060&r2=283061&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Sat Oct 1 21:10:45 2016 @@ -1591,15 +1591,8 @@ static void getPPCTargetFeatures(const D handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group); ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args); - if (FloatABI == ppc::FloatABI::Soft && - !(Triple.getArch() == llvm::Triple::ppc64 || - Triple.getArch() == llvm::Triple::ppc64le)) - Features.push_back("+soft-float"); - else if (FloatABI == ppc::FloatABI::Soft && - (Triple.getArch() == llvm::Triple::ppc64 || - Triple.getArch() == llvm::Triple::ppc64le)) - D.Diag(diag::err_drv_invalid_mfloat_abi) - << "soft float is not supported for ppc64"; + if (FloatABI == ppc::FloatABI::Soft) + Features.push_back("-hard-float"); // Altivec is a bit weird, allow overriding of the Altivec feature here. AddTargetFeature(Args, Features, options::OPT_faltivec, Added: cfe/trunk/test/CodeGen/ppc64-soft-float.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc64-soft-float.c?rev=283061&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/ppc64-soft-float.c (added) +++ cfe/trunk/test/CodeGen/ppc64-soft-float.c Sat Oct 1 21:10:45 2016 @@ -0,0 +1,171 @@ +// RUN: %clang_cc1 -msoft-float -mfloat-abi soft -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-LE %s +// RUN: %clang_cc1 -msoft-float -mfloat-abi soft -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-BE %s + +// Test float returns and params. + +// CHECK: define float @func_p1(float %x) +float func_p1(float x) { return x; } + +// CHECK: define double @func_p2(double %x) +double func_p2(double x) { return x; } + +// CHECK: define ppc_fp128 @func_p3(ppc_fp128 %x) +long double func_p3(long double x) { return x; } + +// Test homogeneous float aggregate passing and returning. + +struct f1 { float f[1]; }; +struct f2 { float f[2]; }; +struct f3 { float f[3]; }; +struct f4 { float f[4]; }; +struct f5 { float f[5]; }; +struct f6 { float f[6]; }; +struct f7 { float f[7]; }; +struct f8 { float f[8]; }; +struct f9 { float f[9]; }; + +struct fab { float a; float b; }; +struct fabc { float a; float b; float c; }; + +struct f2a2b { float a[2]; float b[2]; }; + +// CHECK-LE: define i32 @func_f1(float inreg %x.coerce) +// CHECK-BE: define void @func_f1(%struct.f1* noalias sret %agg.result, float inreg %x.coerce) +struct f1 func_f1(struct f1 x) { return x; } + +// CHECK-LE: define i64 @func_f2(i64 %x.coerce) +// CHECK-BE: define void @func_f2(%struct.f2* noalias sret %agg.result, i64 %x.coerce) +struct f2 func_f2(struct f2 x) { return x; } + +// CHECK-LE: define { i64, i64 } @func_f3([2 x i64] %x.coerce) +// CHECK-BE: define void @func_f3(%struct.f3* noalias sret %agg.result, [2 x i64] %x.coerce) +struct f3 func_f3(struct f3 x) { return x; } + +// CHECK-LE: define { i64, i64 } @func_f4([2 x i64] %x.coerce) +// CHECK-BE: define void @func_f4(%struct.f4* noalias sret %agg.result, [2 x i64] %x.coerce) +struct f4 func_f4(struct f4 x) { return x; } + +// CHECK: define void @func_f5(%struct.f5* noalias sret %agg.result, [3 x i64] %x.coerce) +struct f5 func_f5(struct f5 x) { return x; } + +// CHECK: define void @func_f6(%struct.f6* noalias sret %agg.result, [3 x i64] %x.coerce) +struct f6 func_f6(struct f6 x) { return x; } + +// CHECK: define void @func_f7(%struct.f7* noalias sret %agg.result, [4 x i64] %x.coerce) +struct f7 func_f7(struct f7 x) { return x; } + +// CHECK: define void @func_f8(%struct.f8* noalias sret %agg.result, [4 x i64] %x.coerce) +struct f8 func_f8(struct f8 x) { return x; } + +// CHECK: define void @func_f9(%struct.f9* noalias sret %agg.result, [5 x i64] %x.coerce) +struct f9 func_f9(struct f9 x) { return x; } + +// CHECK-LE: define i64 @func_fab(i64 %x.coerce) +// CHECK-BE: define void @func_fab(%struct.fab* noalias sret %agg.result, i64 %x.coerce) +struct fab func_fab(struct fab x) { return x; } + +// CHECK-LE: define { i64, i64 } @func_fabc([2 x i64] %x.coerce) +// CHECK-BE: define void @func_fabc(%struct.fabc* noalias sret %agg.result, [2 x i64] %x.coerce) +struct fabc func_fabc(struct fabc x) { return x; } + +// CHECK-LE: define { i64, i64 } @func_f2a2b([2 x i64] %x.coerce) +// CHECK-BE: define void @func_f2a2b(%struct.f2a2b* noalias sret %agg.result, [2 x i64] %x.coerce) +struct f2a2b func_f2a2b(struct f2a2b x) { return x; } + +// CHECK-LABEL: @call_f1 +// CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f1, align 4 +// CHECK: %[[TMP:[^ ]+]] = load float, float* getelementptr inbounds (%struct.f1, %struct.f1* @global_f1, i32 0, i32 0, i32 0), align 4 +// CHECK-LE: call i32 @func_f1(float inreg %[[TMP]]) +// CHECK-BE: call void @func_f1(%struct.f1* sret %[[TMP0]], float inreg %[[TMP]]) +struct f1 global_f1; +void call_f1(void) { global_f1 = func_f1(global_f1); } + +// CHECK-LABEL: @call_f2 +// CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f2, align 4 +// CHECK: %[[TMP:[^ ]+]] = load i64, i64* bitcast (%struct.f2* @global_f2 to i64*), align 4 +// CHECK-LE: call i64 @func_f2(i64 %[[TMP]]) +// CHECK-BE: call void @func_f2(%struct.f2* sret %[[TMP0]], i64 %[[TMP]]) +struct f2 global_f2; +void call_f2(void) { global_f2 = func_f2(global_f2); } + +// CHECK-LABEL: @call_f3 +// CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f3, align 4 +// CHECK: %[[TMP1:[^ ]+]] = alloca [2 x i64] +// CHECK: %[[TMP2:[^ ]+]] = bitcast [2 x i64]* %[[TMP1]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[TMP2]], i8* bitcast (%struct.f3* @global_f3 to i8*), i64 12, i32 4, i1 false) +// CHECK: %[[TMP3:[^ ]+]] = load [2 x i64], [2 x i64]* %[[TMP1]] +// CHECK-LE: call { i64, i64 } @func_f3([2 x i64] %[[TMP3]]) +// CHECK-BE: call void @func_f3(%struct.f3* sret %[[TMP0]], [2 x i64] %[[TMP3]]) +struct f3 global_f3; +void call_f3(void) { global_f3 = func_f3(global_f3); } + +// CHECK-LABEL: @call_f4 +// CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f4, align 4 +// CHECK: %[[TMP:[^ ]+]] = load [2 x i64], [2 x i64]* bitcast (%struct.f4* @global_f4 to [2 x i64]*), align 4 +// CHECK-LE: call { i64, i64 } @func_f4([2 x i64] %[[TMP]]) +// CHECK-BE: call void @func_f4(%struct.f4* sret %[[TMP0]], [2 x i64] %[[TMP]]) +struct f4 global_f4; +void call_f4(void) { global_f4 = func_f4(global_f4); } + +// CHECK-LABEL: @call_f5 +// CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f5, align 4 +// CHECK: %[[TMP1:[^ ]+]] = alloca [3 x i64] +// CHECK: %[[TMP2:[^ ]+]] = bitcast [3 x i64]* %[[TMP1]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[TMP2]], i8* bitcast (%struct.f5* @global_f5 to i8*), i64 20, i32 4, i1 false) +// CHECK: %[[TMP3:[^ ]+]] = load [3 x i64], [3 x i64]* %[[TMP1]] +// CHECK: call void @func_f5(%struct.f5* sret %[[TMP0]], [3 x i64] %[[TMP3]]) +struct f5 global_f5; +void call_f5(void) { global_f5 = func_f5(global_f5); } + +// CHECK-LABEL: @call_f6 +// CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f6, align 4 +// CHECK: %[[TMP:[^ ]+]] = load [3 x i64], [3 x i64]* bitcast (%struct.f6* @global_f6 to [3 x i64]*), align 4 +// CHECK: call void @func_f6(%struct.f6* sret %[[TMP0]], [3 x i64] %[[TMP]]) +struct f6 global_f6; +void call_f6(void) { global_f6 = func_f6(global_f6); } + +// CHECK-LABEL: @call_f7 +// CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f7, align 4 +// CHECK: %[[TMP1:[^ ]+]] = alloca [4 x i64], align 8 +// CHECK: %[[TMP2:[^ ]+]] = bitcast [4 x i64]* %[[TMP1]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[TMP2]], i8* bitcast (%struct.f7* @global_f7 to i8*), i64 28, i32 4, i1 false) +// CHECK: %[[TMP3:[^ ]+]] = load [4 x i64], [4 x i64]* %[[TMP1]], align 8 +// CHECK: call void @func_f7(%struct.f7* sret %[[TMP0]], [4 x i64] %[[TMP3]]) +struct f7 global_f7; +void call_f7(void) { global_f7 = func_f7(global_f7); } + +// CHECK-LABEL: @call_f8 +// CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f8, align 4 +// CHECK: %[[TMP:[^ ]+]] = load [4 x i64], [4 x i64]* bitcast (%struct.f8* @global_f8 to [4 x i64]*), align 4 +// CHECK: call void @func_f8(%struct.f8* sret %[[TMP0]], [4 x i64] %[[TMP]]) +struct f8 global_f8; +void call_f8(void) { global_f8 = func_f8(global_f8); } + +// CHECK-LABEL: @call_f9 +// CHECK: %[[TMP1:[^ ]+]] = alloca [5 x i64] +// CHECK: %[[TMP2:[^ ]+]] = bitcast [5 x i64]* %[[TMP1]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[TMP2]], i8* bitcast (%struct.f9* @global_f9 to i8*), i64 36, i32 4, i1 false) +// CHECK: %[[TMP3:[^ ]+]] = load [5 x i64], [5 x i64]* %[[TMP1]] +// CHECK: call void @func_f9(%struct.f9* sret %{{[^ ]+}}, [5 x i64] %[[TMP3]]) +struct f9 global_f9; +void call_f9(void) { global_f9 = func_f9(global_f9); } + +// CHECK-LABEL: @call_fab +// CHECK: %[[TMP0:[^ ]+]] = alloca %struct.fab, align 4 +// CHECK: %[[TMP:[^ ]+]] = load i64, i64* bitcast (%struct.fab* @global_fab to i64*), align 4 +// CHECK-LE: %call = call i64 @func_fab(i64 %[[TMP]]) +// CHECK-BE: call void @func_fab(%struct.fab* sret %[[TMP0]], i64 %[[TMP]]) +struct fab global_fab; +void call_fab(void) { global_fab = func_fab(global_fab); } + +// CHECK-LABEL: @call_fabc +// CHECK-BE: %[[TMPX:[^ ]+]] = alloca %struct.fabc, align 4 +// CHECK: %[[TMP0:[^ ]+]] = alloca [2 x i64], align 8 +// CHECK: %[[TMP2:[^ ]+]] = bitcast [2 x i64]* %[[TMP0]] to i8* +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[TMP2]], i8* bitcast (%struct.fabc* @global_fabc to i8*), i64 12, i32 4, i1 false) +// CHECK: %[[TMP3:[^ ]+]] = load [2 x i64], [2 x i64]* %[[TMP0]], align 8 +// CHECK-LE: %call = call { i64, i64 } @func_fabc([2 x i64] %[[TMP3]]) +// CHECK-BE: call void @func_fabc(%struct.fabc* sret %[[TMPX]], [2 x i64] %[[TMP3]]) +struct fabc global_fabc; +void call_fabc(void) { global_fabc = func_fabc(global_fabc); } + Modified: cfe/trunk/test/Driver/ppc-features.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-features.cpp?rev=283061&r1=283060&r2=283061&view=diff ============================================================================== --- cfe/trunk/test/Driver/ppc-features.cpp (original) +++ cfe/trunk/test/Driver/ppc-features.cpp Sat Oct 1 21:10:45 2016 @@ -14,27 +14,27 @@ // check -msoft-float option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTFLOAT %s -// CHECK-SOFTFLOAT: "-target-feature" "+soft-float" +// CHECK-SOFTFLOAT: "-target-feature" "-hard-float" // check -mfloat-abi=soft option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=soft -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABISOFT %s -// CHECK-FLOATABISOFT: "-target-feature" "+soft-float" +// CHECK-FLOATABISOFT: "-target-feature" "-hard-float" // check -mhard-float option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDFLOAT %s -// CHECK-HARDFLOAT-NOT: "-target-feature" "+soft-float" +// CHECK-HARDFLOAT-NOT: "-target-feature" "-hard-float" // check -mfloat-abi=hard option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=hard -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABIHARD %s -// CHECK-FLOATABIHARD-NOT: "-target-feature" "+soft-float" +// CHECK-FLOATABIHARD-NOT: "-target-feature" "-hard-float" // check combine -mhard-float -msoft-float option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mhard-float -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-HARDSOFT %s -// CHECK-HARDSOFT: "-target-feature" "+soft-float" +// CHECK-HARDSOFT: "-target-feature" "-hard-float" // check combine -msoft-float -mhard-float option for ppc32 // RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s -// CHECK-SOFTHARD-NOT: "-target-feature" "+soft-float" +// CHECK-SOFTHARD-NOT: "-target-feature" "-hard-float" // check -mfloat-abi=x option // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=x -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-ERRMSG %s @@ -42,19 +42,19 @@ // check -msoft-float option for ppc64 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTFLOAT64 %s -// CHECK-SOFTFLOAT64: error: invalid float ABI 'soft float is not supported for ppc64' +// CHECK-SOFTFLOAT64: "-target-feature" "-hard-float" // check -mfloat-abi=soft option for ppc64 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mfloat-abi=soft -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABISOFT64 %s -// CHECK-FLOATABISOFT64: error: invalid float ABI 'soft float is not supported for ppc64' +// CHECK-FLOATABISOFT64: "-target-feature" "-hard-float" // check -msoft-float option for ppc64 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -msoft-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTFLOAT64le %s -// CHECK-SOFTFLOAT64le: error: invalid float ABI 'soft float is not supported for ppc64' +// CHECK-SOFTFLOAT64le: "-target-feature" "-hard-float" // check -mfloat-abi=soft option for ppc64 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -mfloat-abi=soft -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-FLOATABISOFT64le %s -// CHECK-FLOATABISOFT64le: error: invalid float ABI 'soft float is not supported for ppc64' +// CHECK-FLOATABISOFT64le: "-target-feature" "-hard-float" // CHECK: invalid argument '-faltivec' only allowed with 'ppc/ppc64/ppc64le' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits