[PATCH] D90174: [HIP] Fix regressions due to fp contract change

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 10:57:00 PDT 2020


yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall.
Herald added a subscriber: tpr.
yaxunl requested review of this revision.

Recently HIP toolchain made a change to use clang instead of opt/llc to do compilation
(https://reviews.llvm.org/D81861). The intention is to make HIP toolchain canonical like
other toolchains.

However, this change introduced an unintentional change regarding backend fp fuse
option, which caused regressions in some HIP applications.

Basically before the change, HIP toolchain used clang to generate bitcode, then use
opt/llc to optimize bitcode and generate ISA. As such, the amdgpu backend takes
the default fp fuse mode which is 'Standard'. This mode respect contract flag of
fmul/fadd instructions and do not fuse fmul/fadd instructions without contract flag.

However, after the change, HIP toolchain now use clang to generate IR, do optimization,
and generate ISA as one process. Now amdgpu backend fp fuse option is determined
by -ffp-contract option, which is 'fast' by default. And this -ffp-contract=fast language option
is translated to 'Fast' fp fuse option in backend. Suddenly backend starts to fuse fmul/fadd
instructions without contract flag.

This causes wrong result for some device library functions, e.g. tan(-1e20), which should
return 0.8446, now returns -0.933. What is worse is that since backend with 'Fast' fp fuse
option does not respect contract flag, there is no way to use #pragma clang fp contract
directive to enforce fp contract requirements.

This patch fixes the regression by forcing the backend to use 'Standard' fp fuse option
for HIP. I think it is a reasonable change before we have a better solution. Since 'Fast'
fp fuse option in backend does not respect contract flag, it is of little use to HIP
applications since all code with #pragma STDC FP_CONTRACT or any IR from a
source compiled with -ffp-contract=on is broken.


https://reviews.llvm.org/D90174

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGenCUDA/fp-contract.cu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90174.300725.patch
Type: text/x-patch
Size: 11945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/fa224b30/attachment.bin>


More information about the cfe-commits mailing list