@@ -2942,6 +2942,14 @@ static void EmitComplexRangeDiag(const Driver &D, std::string str1,
29422942 }
29432943}
29442944
2945+ static void EmitAccuracyDiag (const Driver &D, const JobAction &JA,
2946+ StringRef AccuracValStr, StringRef TargetPrecStr) {
2947+ if (JA.isDeviceOffloading (Action::OFK_SYCL)) {
2948+ D.Diag (clang::diag::warn_acuracy_conflicts_with_explicit_target_prec_option)
2949+ << AccuracValStr << TargetPrecStr;
2950+ }
2951+ }
2952+
29452953static std::string
29462954RenderComplexRangeOption (LangOptions::ComplexRangeKind Range) {
29472955 std::string ComplexRangeStr = ComplexRangeKindToStr (Range);
@@ -2950,6 +2958,14 @@ RenderComplexRangeOption(LangOptions::ComplexRangeKind Range) {
29502958 return ComplexRangeStr;
29512959}
29522960
2961+ static bool shouldUsePreciseDivision (const ArgList &Args) {
2962+ return Args.hasArg (options::OPT_ftarget_prec_div);
2963+ }
2964+
2965+ static bool shouldUsePreciseSqrt (const ArgList &Args) {
2966+ return Args.hasArg (options::OPT_ftarget_prec_sqrt);
2967+ }
2968+
29532969static void RenderFloatingPointOptions (const ToolChain &TC, const Driver &D,
29542970 bool OFastEnabled, const ArgList &Args,
29552971 ArgStringList &CmdArgs,
@@ -2998,6 +3014,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
29983014 LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
29993015 std::string ComplexRangeStr = " " ;
30003016 std::string GccRangeComplexOption = " " ;
3017+ bool NoTargetPrecDiv = false ;
3018+ bool NoTargetPrecSqrt = false ;
30013019
30023020 // Lambda to set fast-math options. This is also used by -ffp-model=fast
30033021 auto applyFastMath = [&]() {
@@ -3060,6 +3078,19 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30603078 // If this isn't an FP option skip the claim below
30613079 default : continue ;
30623080
3081+ case options::OPT_ftarget_prec_div:
3082+ case options::OPT_ftarget_prec_sqrt:
3083+ break ;
3084+ case options::OPT_fno_target_prec_sqrt:
3085+ if (!FPAccuracy.empty ())
3086+ EmitAccuracyDiag (D, JA, FPAccuracy, " -fno-target-prec-sqrt" );
3087+ NoTargetPrecSqrt = true ;
3088+ break ;
3089+ case options::OPT_fno_target_prec_div:
3090+ if (!FPAccuracy.empty ())
3091+ EmitAccuracyDiag (D, JA, FPAccuracy, " -fno-target-prec-div" );
3092+ NoTargetPrecDiv = true ;
3093+ break ;
30633094 case options::OPT_fcx_limited_range:
30643095 if (GccRangeComplexOption.empty ()) {
30653096 if (Range != LangOptions::ComplexRangeKind::CX_Basic)
@@ -3144,6 +3175,10 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31443175 case options::OPT_ffp_accuracy_EQ: {
31453176 StringRef Val = A->getValue ();
31463177 FPAccuracy = Val;
3178+ if (NoTargetPrecDiv)
3179+ EmitAccuracyDiag (D, JA, FPAccuracy, " -fno-target-prec-div" );
3180+ if (NoTargetPrecSqrt)
3181+ EmitAccuracyDiag (D, JA, FPAccuracy, " -fno-target-prec-sqrt" );
31473182 break ;
31483183 }
31493184 case options::OPT_ffp_model_EQ: {
@@ -3176,6 +3211,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31763211 applyFastMath ();
31773212 // applyFastMath sets fp-contract="fast"
31783213 LastFpContractOverrideOption = " -ffp-model=fast" ;
3214+ if (JA.isDeviceOffloading (Action::OFK_SYCL)) {
3215+ // when fp-model=fast is used the default precision for division and
3216+ // sqrt is not precise.
3217+ NoTargetPrecDiv = shouldUsePreciseDivision (Args);
3218+ NoTargetPrecSqrt = shouldUsePreciseSqrt (Args);
3219+ }
31793220 } else if (Val == " precise" ) {
31803221 FPModel = Val;
31813222 FPContract = " on" ;
@@ -3557,6 +3598,16 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
35573598 CmdArgs.push_back (" -fno-cx-limited-range" );
35583599 if (Args.hasArg (options::OPT_fno_cx_fortran_rules))
35593600 CmdArgs.push_back (" -fno-cx-fortran-rules" );
3601+ if (JA.isDeviceOffloading (Action::OFK_SYCL)) {
3602+ if (NoTargetPrecDiv)
3603+ CmdArgs.push_back (" -fno-target-prec-div" );
3604+ else
3605+ CmdArgs.push_back (" -ftarget-prec-div" );
3606+ if (NoTargetPrecSqrt)
3607+ CmdArgs.push_back (" -fno-target-prec-sqrt" );
3608+ else
3609+ CmdArgs.push_back (" -ftarget-prec-sqrt" );
3610+ }
35603611}
35613612
35623613static void RenderAnalyzerOptions (const ArgList &Args, ArgStringList &CmdArgs,
0 commit comments