-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL] Add support for -foffload-fp32-prec-div/sqrt options. #15836
base: sycl
Are you sure you want to change the base?
Changes from 18 commits
f8caf83
00ffb5a
795dd38
78a9005
50e71c0
54f2409
bdf78d7
8cd6d8b
755d630
27011c8
ff2b3d9
07752e2
aa909d2
fcc4786
24711fd
56314b7
e643027
b25e5ac
ce00296
bc01759
c5fffc5
f2fb8b2
83c9b31
0efc825
e1de775
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1879,25 +1879,44 @@ void CodeGenModule::getDefaultFunctionFPAccuracyAttributes( | |
// the 'FPAccuracyFuncMap'; if no accuracy is mapped to Name (FuncAttrs | ||
// is empty), then set its accuracy from the TU's accuracy value. | ||
if (!getLangOpts().FPAccuracyFuncMap.empty()) { | ||
StringRef FPAccuracyVal; | ||
auto FuncMapIt = getLangOpts().FPAccuracyFuncMap.find(Name.str()); | ||
if (FuncMapIt != getLangOpts().FPAccuracyFuncMap.end()) { | ||
StringRef FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin( | ||
ID, FuncType, convertFPAccuracy(FuncMapIt->second)); | ||
if (!getLangOpts().OffloadFP32PrecDiv && Name == "fdiv") | ||
FPAccuracyVal = "2.5"; | ||
else if (!getLangOpts().OffloadFP32PrecSqrt && Name == "sqrt") | ||
FPAccuracyVal = "3.0"; | ||
else | ||
FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin( | ||
ID, FuncType, convertFPAccuracy(FuncMapIt->second)); | ||
assert(!FPAccuracyVal.empty() && "A valid accuracy value is expected"); | ||
FuncAttrs.addAttribute("fpbuiltin-max-error", FPAccuracyVal); | ||
MD = llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( | ||
Int32Ty, convertFPAccuracyToAspect(FuncMapIt->second))); | ||
} | ||
} | ||
if (FuncAttrs.attrs().size() == 0) | ||
if (FuncAttrs.attrs().size() == 0) { | ||
if (!getLangOpts().FPAccuracyVal.empty()) { | ||
StringRef FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin( | ||
ID, FuncType, convertFPAccuracy(getLangOpts().FPAccuracyVal)); | ||
StringRef FPAccuracyVal; | ||
if (!getLangOpts().OffloadFP32PrecDiv && Name == "fdiv") | ||
FPAccuracyVal = "2.5"; | ||
else if (!getLangOpts().OffloadFP32PrecSqrt && Name == "sqrt") | ||
FPAccuracyVal = "3.0"; | ||
else | ||
FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin( | ||
ID, FuncType, convertFPAccuracy(getLangOpts().FPAccuracyVal)); | ||
assert(!FPAccuracyVal.empty() && "A valid accuracy value is expected"); | ||
FuncAttrs.addAttribute("fpbuiltin-max-error", FPAccuracyVal); | ||
MD = llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( | ||
Int32Ty, convertFPAccuracyToAspect(getLangOpts().FPAccuracyVal))); | ||
} else { | ||
if (!getLangOpts().OffloadFP32PrecDiv && Name == "fdiv") { | ||
FuncAttrs.addAttribute("fpbuiltin-max-error", "2.5"); | ||
} else if (!getLangOpts().OffloadFP32PrecSqrt && Name == "sqrt") { | ||
FuncAttrs.addAttribute("fpbuiltin-max-error", "3.0"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Add denormal-fp-math and denormal-fp-math-f32 as appropriate for the | ||
|
@@ -5790,10 +5809,20 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, | |
// Emit the actual call/invoke instruction. | ||
llvm::CallBase *CI; | ||
if (!InvokeDest) { | ||
if (!getLangOpts().FPAccuracyFuncMap.empty() || | ||
!getLangOpts().FPAccuracyVal.empty()) { | ||
const auto *FD = dyn_cast_if_present<FunctionDecl>(TargetDecl); | ||
if (FD && FD->getNameInfo().getName().isIdentifier()) { | ||
const auto *FD = dyn_cast_if_present<FunctionDecl>(TargetDecl); | ||
if (FD && FD->getNameInfo().getName().isIdentifier()) { | ||
StringRef FuncName = FD->getName(); | ||
const bool IsFloat32Type = FD->getReturnType()->isFloat32Type(); | ||
bool hasFPAccuracyFuncMap = hasAccuracyRequirement(FuncName); | ||
bool hasFPAccuracyVal = !getLangOpts().FPAccuracyVal.empty(); | ||
bool isFp32SqrtFunction = | ||
(FuncName == "sqrt" && !getLangOpts().OffloadFP32PrecSqrt && | ||
IsFloat32Type); | ||
bool isFP32FdivFunction = | ||
(FuncName == "fdiv" && !getLangOpts().OffloadFP32PrecDiv && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually though, that the request is done to replace fdiv instruction with the intrinsic, not fdiv function. Do we know if users actually use such function? I don't see any mentioning of it in SYCL or OpenCL specifications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gmlueck could you please comment on that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK there is no standard function float FP division. There is std::div, but it works only on integers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no C/C++ fdiv function. |
||
IsFloat32Type); | ||
if (hasFPAccuracyFuncMap || hasFPAccuracyVal || isFp32SqrtFunction || | ||
isFP32FdivFunction) { | ||
CI = MaybeEmitFPBuiltinofFD(IRFuncTy, IRCallArgs, CalleePtr, | ||
FD->getName(), FD->getBuiltinID()); | ||
if (CI) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we compare with un-mangled sqrt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FuncName is the output of FD->getName() which returns a simple identifier. https://github.com/intel/llvm/blob/sycl/clang/include/clang/AST/Decl.h#L280
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So clang/test/CodeGenSYCL/offload-fp32-div-sqrt.cpp will pass even with
extern "C"
removed fromsqrt
function declaration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user has a function in their own namespace that happens to be named "sqrt"?