We want the !fpmath metadata to be attached to the sqrt intrinsic to
make it to the backend lowering. Emit an available_externally
definition which uses the builtin, which emits the !fpmath.
Fixes #64264
Paths
| Differential D156743
clang/OpenCL: Add inline implementations of sqrt in builtin header ClosedPublic Authored by arsenm on Jul 31 2023, 2:15 PM.
Details
Diff Detail Event Timelinearsenm retitled this revision from [wip] clang/OpenCL: Add inline implementations of sqrt in builtin header to clang/OpenCL: Add inline implementations of sqrt in builtin header. Comment ActionsMove to base header and fix test. update_cc_test_checks --include-generated-funcs does a terrible job here so write manually checks
Comment Actions If we go with this approach, please also remove sqrt from clang/lib/Sema/OpenCLBuiltins.td (and ideally add a comment pointing out that sqrt is handled in opencl-c-base.h)
arsenm marked an inline comment as done. arsenm added inline comments.
Comment Actions ping The alternative is to directly put the !fpmath on the sqrt call sites but I have no idea how to do that Comment Actions If we think there are no better alternatives and implementation is generic enough for every vendor, LGTM! This revision is now accepted and ready to land.Sep 12 2023, 7:06 AM Comment Actions
You could argue annotating the raw callsite is better but I don't know how to implement that
Revision Contents
Diff 546164 clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
clang/test/CodeGenCUDA/correctly-rounded-div.cu
clang/test/CodeGenOpenCL/fpmath.cl
clang/test/CodeGenOpenCL/sqrt-fpmath.cl
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp
|
Is this a generic implementation enough? Would some targets not need to do something different for this built-in?
Ideally this header is to be kept light so I am a bit worried about adding definitions of the functions here. Otherwise we will end up in the same situation as we one day were with opencl-c.h. So could these be left there instead? It might be good to check with @svenvh if TableGen header has already a way to do this function forwarding or can be extended to do such a thing. Then it would be implementable in the both header mechanisms. I don't know if Sven has some other ideas or opinions...