This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix missing contract flag in sqrt intrinsic
ClosedPublic

Authored by yaxunl on Aug 23 2023, 8:46 PM.

Details

Reviewers
arsenm
rjmccall
Summary

The fp options specified through pragma are already encoded in Expr.

This patch takes the same approach used by clang codegen to emit fastmath flags for fadd insts, basically use RAII to set the current fastmath flags in IRBuilder, which is then used to emit sqrt intrinsic.

Fix: https://github.com/llvm/llvm-project/issues/64653

Diff Detail

Event Timeline

yaxunl created this revision.Aug 23 2023, 8:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 8:46 PM
yaxunl requested review of this revision.Aug 23 2023, 8:46 PM
yaxunl edited the summary of this revision. (Show Details)Aug 23 2023, 9:11 PM
rjmccall added inline comments.Aug 23 2023, 11:26 PM
clang/lib/CodeGen/CGBuiltin.cpp
499–500

Is this existing condition not good enough, and why?

arsenm added inline comments.Aug 24 2023, 4:06 AM
clang/test/CodeGen/fp-contract-fast-pragma.cpp
18

Should leave the existing test function alone and add a new one. Also can you test some cases with nested different values

arsenm added inline comments.Aug 24 2023, 4:07 AM
clang/lib/CodeGen/CGBuiltin.cpp
499–500

It's only in the strictfp branch for some reason, I don't think both would be needed

clang/test/CodeGen/fp-contract-fast-pragma.cpp
8

Should also check constrained run line

yaxunl marked 4 inline comments as done.Aug 24 2023, 8:22 AM
yaxunl added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
499–500

It seems I just need to move the RAII out of that condition.

clang/test/CodeGen/fp-contract-fast-pragma.cpp
8

will do

18

pragma clang fp cannot be used inside compound statements. It is only allowed in either function scope or at the beginning of a compound statement. Essentially, it can only enable/disable contracting at a granularity of the function level. I can add a test for enabling/disabling it in different functions.

yaxunl updated this revision to Diff 553141.Aug 24 2023, 8:23 AM
yaxunl marked 3 inline comments as done.

revised by comments

arsenm added inline comments.Aug 24 2023, 8:47 AM
clang/test/CodeGen/fp-contract-fast-pragma.cpp
94

This isn't demonstrating the strict support, probably need to add the pragma fenv_access for the -fexperimental-strict-floating-point run line

Code change LGTM; I'll let you hash out the test feedback.

yaxunl updated this revision to Diff 553250.Aug 24 2023, 1:55 PM

fix test for strict fp

arsenm accepted this revision.Aug 24 2023, 2:03 PM
This revision is now accepted and ready to land.Aug 24 2023, 2:03 PM
yaxunl closed this revision.Aug 24 2023, 4:20 PM