-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL] Add support for -foffload-fp32-prec-div/sqrt options. #15836
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
Changes from 21 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
34f07cc
e18930f
410856d
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 == "div") | ||
| 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 == "div") | ||
| 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 == "div") { | ||
| 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,16 @@ 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 && | ||
|
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. Why do we compare with un-mangled sqrt? 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. 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 commentThe 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 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. What if the user has a function in their own namespace that happens to be named "sqrt"? |
||
| IsFloat32Type); | ||
| if (hasFPAccuracyFuncMap || hasFPAccuracyVal || isFp32SqrtFunction) { | ||
| CI = MaybeEmitFPBuiltinofFD(IRFuncTy, IRCallArgs, CalleePtr, | ||
| FD->getName(), FD->getBuiltinID()); | ||
| if (CI) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.