Skip to content

Commit 75a6d09

Browse files
authored
[SYCL][FE][Driver] Re-enable fp-accuracy tests (#9978)
Both issues were due to the DoRoundTrip value (1 in debug compile and 0 in release compile). Diagnostics were generated in a function dependent on the value of DoRoundTrip and that had the effect of generating no diagnostic in release mode, but diagnostics were fired in debug more in the second run on the function RoundTrip. Same for the setting of the codegen’s FPAccuracy option. Changes: 1- Removed un-necessary FPaccuracy codegen option; used instead the values of FpAccuracyVal and FPAccuracyFuncMap. 2- Changed place to the diagnostics. @AaronBallman what do you think of the placement of the diagnostics? Is this acceptable for potential upstream? Fixes: #9934
1 parent 5d3d54b commit 75a6d09

File tree

6 files changed

+49
-55
lines changed

6 files changed

+49
-55
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ CODEGENOPT(VirtualFunctionElimination, 1, 0) ///< Whether to apply the dead
373373
/// virtual function elimination
374374
/// optimization.
375375

376-
/// Whether accuracy levels for math library functions are requested by the
377-
/// user. These accuracy levels will then be expressed in terms of ULPs.
378-
CODEGENOPT(FPAccuracy, 1, 0)
379-
380376
/// Whether to use public LTO visibility for entities in std and stdext
381377
/// namespaces. This is enabled by clang-cl's /MT and /MTd flags.
382378
CODEGENOPT(LTOVisibilityPublicStd, 1, 0)

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -537,33 +537,45 @@ static bool hasAccuracyRequirement(CodeGenFunction &CGF, StringRef Name) {
537537
return FuncMapIt != CGF.getLangOpts().FPAccuracyFuncMap.end();
538538
}
539539

540-
// Emit a simple mangled intrinsic that has 1 argument and a return type
541-
// matching the argument type. Depending on mode, this may be a constrained
542-
// or an fpbuiltin floating-point intrinsic.
543-
static Value *emitUnaryMaybeConstrainedFPBuiltin(
544-
CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID,
545-
unsigned ConstrainedIntrinsicID,
546-
unsigned FPAccuracyIntrinsicID = Intrinsic::not_intrinsic) {
547-
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
540+
static Function *emitMaybeIntrinsic(CodeGenFunction &CGF, const CallExpr *E,
541+
unsigned FPAccuracyIntrinsicID,
542+
unsigned IntrinsicID, llvm::Value *Src0,
543+
StringRef &Name) {
544+
Function *Func = nullptr;
548545
if (FPAccuracyIntrinsicID != Intrinsic::not_intrinsic) {
549-
if (CGF.CGM.getCodeGenOpts().FPAccuracy) {
546+
if (!CGF.getLangOpts().FPAccuracyVal.empty() ||
547+
!CGF.getLangOpts().FPAccuracyFuncMap.empty()) {
550548
if (CGF.getLangOpts().MathErrno) {
551549
DiagnosticsEngine &Diags = CGF.CGM.getDiags();
552550
Diags.Report(E->getBeginLoc(), diag::err_drv_incompatible_options)
553551
<< "-ffp-accuracy"
554552
<< "-fmath-errno";
555553
} else {
556-
StringRef Name =
554+
Name =
557555
CGF.CGM.getContext().BuiltinInfo.getName(CGF.getCurrentBuiltinID());
558556
// Use fpbuiltin intrinsic only when needed.
559-
Function *Func =
560-
getIntrinsic(CGF, Src0, FPAccuracyIntrinsicID, IntrinsicID,
561-
hasAccuracyRequirement(CGF, Name));
562-
return CreateBuiltinCallWithAttr(CGF, Name, Func, {Src0},
563-
FPAccuracyIntrinsicID);
557+
Func = getIntrinsic(CGF, Src0, FPAccuracyIntrinsicID, IntrinsicID,
558+
hasAccuracyRequirement(CGF, Name));
564559
}
565560
}
566561
}
562+
return Func;
563+
}
564+
565+
// Emit a simple mangled intrinsic that has 1 argument and a return type
566+
// matching the argument type. Depending on mode, this may be a constrained
567+
// or an fpbuiltin floating-point intrinsic.
568+
static Value *emitUnaryMaybeConstrainedFPBuiltin(
569+
CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID,
570+
unsigned ConstrainedIntrinsicID,
571+
unsigned FPAccuracyIntrinsicID = Intrinsic::not_intrinsic) {
572+
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
573+
StringRef Name;
574+
Function *Func = emitMaybeIntrinsic(CGF, E, FPAccuracyIntrinsicID,
575+
IntrinsicID, Src0, Name);
576+
if (Func)
577+
return CreateBuiltinCallWithAttr(CGF, Name, Func, {Src0},
578+
FPAccuracyIntrinsicID);
567579
if (CGF.Builder.getIsFPConstrained()) {
568580
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
569581
Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
@@ -582,15 +594,12 @@ static Value *emitBinaryMaybeConstrainedFPBuiltin(
582594
unsigned FPAccuracyIntrinsicID = Intrinsic::not_intrinsic) {
583595
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
584596
llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
585-
if (CGF.CGM.getCodeGenOpts().FPAccuracy) {
586-
StringRef Name =
587-
CGF.CGM.getContext().BuiltinInfo.getName(CGF.getCurrentBuiltinID());
588-
// Use fpbuiltin intrinsic only when needed.
589-
Function *Func = getIntrinsic(CGF, Src0, FPAccuracyIntrinsicID, IntrinsicID,
590-
hasAccuracyRequirement(CGF, Name));
597+
StringRef Name;
598+
Function *Func = emitMaybeIntrinsic(CGF, E, FPAccuracyIntrinsicID,
599+
IntrinsicID, Src0, Name);
600+
if (Func)
591601
return CreateBuiltinCallWithAttr(CGF, Name, Func, {Src0, Src1},
592602
FPAccuracyIntrinsicID);
593-
}
594603
if (CGF.Builder.getIsFPConstrained()) {
595604
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
596605
Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5620,7 +5620,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56205620
// Emit the actual call/invoke instruction.
56215621
llvm::CallBase *CI;
56225622
if (!InvokeDest) {
5623-
if (CGM.getCodeGenOpts().FPAccuracy) {
5623+
if (!getLangOpts().FPAccuracyFuncMap.empty() ||
5624+
!getLangOpts().FPAccuracyVal.empty()) {
56245625
const auto *FD = dyn_cast_if_present<FunctionDecl>(TargetDecl);
56255626
assert(FD && "expecting a function");
56265627
CI = EmitFPBuiltinIndirectCall(IRFuncTy, IRCallArgs, CalleePtr, FD);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
504504
LangOpts.NewAlignOverride = 0;
505505
}
506506

507+
// Diagnose FPAccuracy option validity.
508+
if (!LangOpts.FPAccuracyVal.empty())
509+
for (const auto &F : LangOpts.FPAccuracyFuncMap)
510+
Diags.Report(diag::warn_function_fp_accuracy_already_set)
511+
<< F.second << F.first;
512+
507513
// Prevent the user from specifying both -fsycl-is-device and -fsycl-is-host.
508514
if (LangOpts.SYCLIsDevice && LangOpts.SYCLIsHost)
509515
Diags.Report(diag::err_drv_argument_not_allowed_with) << "-fsycl-is-device"
@@ -2034,9 +2040,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
20342040
}
20352041
}
20362042

2037-
if (Args.getLastArg(options::OPT_ffp_builtin_accuracy_EQ))
2038-
Opts.FPAccuracy = 1;
2039-
20402043
if (auto *arg =
20412044
Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
20422045
auto ResultOrErr = parseToleranceOption(arg->getValue());
@@ -3620,22 +3623,12 @@ void CompilerInvocation::ParseFpAccuracyArgs(LangOptions &Opts, ArgList &Args,
36203623
if (FuncName.back() == ']')
36213624
FuncName = FuncName.drop_back(1);
36223625
auto FuncMap = Opts.FPAccuracyFuncMap.find(FuncName.str());
3623-
if (FuncMap != Opts.FPAccuracyFuncMap.end()) {
3624-
if (!FuncMap->second.empty()) {
3625-
Diags.Report(diag::warn_function_fp_accuracy_already_set)
3626-
<< FuncMap->second << FuncName.str();
3627-
}
3628-
} else {
3629-
checkFPAccuracyIsValid(ValElement[0], Diags);
3630-
if (!Opts.FPAccuracyVal.empty())
3631-
Diags.Report(diag::warn_function_fp_accuracy_already_set)
3632-
<< Opts.FPAccuracyVal << FuncName.str();
3633-
// No need to fill the map if the FPaccuracy is 'default'.
3634-
// The default builtin will be generated.
3635-
if (!ValElement[0].equals("default"))
3636-
Opts.FPAccuracyFuncMap.insert(
3637-
{FuncName.str(), ValElement[0].str()});
3638-
}
3626+
checkFPAccuracyIsValid(ValElement[0], Diags);
3627+
// No need to fill the map if the FPaccuracy is 'default'.
3628+
// The default builtin will be generated.
3629+
if (!ValElement[0].equals("default"))
3630+
Opts.FPAccuracyFuncMap.insert(
3631+
{FuncName.str(), ValElement[0].str()});
36393632
}
36403633
}
36413634
}

clang/test/CodeGen/fp-accuracy.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
// RUN: -Wno-return-type -Wno-implicit-function-declaration -emit-llvm -o - %s \
3131
// RUN: | FileCheck --check-prefixes=CHECK-DEFAULT %s
3232

33-
// Disabled due to https://github.com/intel/llvm/issues/9934
34-
// UNSUPPORTED: system-linux
35-
3633
#ifdef SPIR
3734
// This is a declaration when compiling with -fsycl to avoid
3835
// the compilation error "function with no prototype cannot use

clang/test/Driver/fp-accuracy.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// RUN: not %clang -Xclang -verify -fno-math-errno -ffp-accuracy=high=[sin] %s 2>& 1 \
3737
// RUN: | FileCheck %s --check-prefixes=ERR-2
3838

39-
// RUN: not %clang -Xclang -verify -fno-math-errno -ffp-accuracy=low:[sin,cos] \
39+
// RUN: not %clang -fno-math-errno -ffp-accuracy=low:[sin,cos] \
4040
// RUN: -ffp-accuracy=high %s 2>&1 \
4141
// RUN: | FileCheck %s --check-prefix=WARN
4242

@@ -48,9 +48,6 @@
4848
// RUN: -fmath-errno %s 2>&1 \
4949
// RUN: | FileCheck %s --check-prefixes=ERR-3
5050

51-
// Disabled due to https://github.com/intel/llvm/issues/9934
52-
// UNSUPPORTED: system-linux
53-
5451
// HIGH: "-ffp-builtin-accuracy=high"
5552
// LOW: "-ffp-builtin-accuracy=low"
5653
// MEDIUM: "-ffp-builtin-accuracy=medium"
@@ -61,6 +58,7 @@
6158
// ERR: (frontend): unsupported argument 'foo' to option '-ffp-accuracy'
6259
// ERR-1: (frontend): unsupported argument 'foo' to option '-ffp-accuracy'
6360
// ERR-2: (frontend): unsupported argument 'high=[sin]' to option '-ffp-accuracy'
64-
// WARN: (frontend): floating point accuracy value of 'high' has already been assigned to function 'cos'
65-
// WARN: (frontend): floating point accuracy value of 'high' has already been assigned to function 'sin'
61+
// WARN: floating point accuracy value of 'low' has already been assigned to function 'cos'
62+
// WARN: floating point accuracy value of 'low' has already been assigned to function 'sin'
63+
6664
// ERR-3: (frontend): floating point accuracy requirements cannot be guaranteed when '-fmath-errno' is enabled; use '-fno-math-errno' to enable floating point accuracy control

0 commit comments

Comments
 (0)