This is an archive of the discontinued LLVM Phabricator instance.

clang: Attach !fpmath metadata to __builtin_sqrt based on language flags
ClosedPublic

Authored by arsenm on Jul 5 2023, 4:42 AM.

Details

Summary

OpenCL and HIP have -cl-fp32-correctly-rounded-divide-sqrt and
-fno-hip-correctly-rounded-divide-sqrt. The corresponding fpmath metadata
was only set on fdiv, and not sqrt. The backend is currently underutilizing
sqrt lowering options, and the responsibility is split between the libraries
and backend and this metadata is needed.

CUDA/NVCC has -prec-div and -prev-sqrt but clang doesn't appear to be
aiming for compatibility with those. Don't know if OpenMP has a similar
control.

Diff Detail

Event Timeline

arsenm created this revision.Jul 5 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 4:42 AM
arsenm requested review of this revision.Jul 5 2023, 4:42 AM
yaxunl added inline comments.Jul 5 2023, 12:59 PM
clang/lib/CodeGen/CGExpr.cpp
5594
arsenm added inline comments.Jul 5 2023, 1:49 PM
clang/lib/CodeGen/CGExpr.cpp
5594

Did that change between versions? In any case I don’t want to change the currently used threshold in this patch. We only need 1.0 anyway

arsenm added inline comments.Jul 5 2023, 2:30 PM
clang/lib/CodeGen/CGExpr.cpp
5594

Oh, I see the threshold is 2.5 for fdiv and 3.0 for sqrt.

arsenm updated this revision to Diff 537737.Jul 6 2023, 8:17 AM

Split div/sqrt handling since they have different values. Also cuda does have unimplemented flags to control these individually. Not sure it's worth trying to merge them into one function

FWIW, I assume we want this also for OpenMP offload.

arsenm added a comment.Jul 7 2023, 4:37 AM

FWIW, I assume we want this also for OpenMP offload.

I'd be surprised if OpenMP let you do this by default

yaxunl accepted this revision.Jul 14 2023, 10:54 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Jul 14 2023, 10:54 AM