This is an archive of the discontinued LLVM Phabricator instance.

[PartiallyInlineLibCalls] Disable sqrt expansion for strictfp.
ClosedPublic

Authored by craig.topper on Jun 17 2021, 11:34 AM.

Details

Summary

This pass emits a floating point compare and a conditional branch,
but if strictfp is enabled we don't emit a constrained compare
intrinsic.

The backend also won't expand the readonly sqrt call this pass inserts
to a sqrt instruction under strictfp. So we end up with 2 libcalls as
seen here. https://godbolt.org/z/oax5zMEWd

Fix these things by disabling the pass.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 17 2021, 11:34 AM
craig.topper requested review of this revision.Jun 17 2021, 11:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2021, 11:34 AM
craig.topper edited the summary of this revision. (Show Details)Jun 17 2021, 11:38 AM
craig.topper edited the summary of this revision. (Show Details)
craig.topper added a subscriber: arcbbb.
kpn added inline comments.Jun 17 2021, 11:46 AM
llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
4

I'm pretty sure this needs the strictfp attribute as well.

8

There is a constrained sqrt. It seems like not emitting it is the real bug.

craig.topper added inline comments.Jun 17 2021, 11:50 AM
llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
8

From the frontend?

Add strictfp to caller in test case.

kpn added inline comments.Jun 17 2021, 12:08 PM
llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
8

A quick check shows that we actually are emitting the constrained sqrt call from clang, at least we are using the arguments from the godbolt link. So I'm not sure how we got here?

craig.topper added inline comments.Jun 17 2021, 1:14 PM
llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
8

We can only emit an intrinsic call if -fno-math-errno is in effect. If we need errno, we must call the library function.

craig.topper added inline comments.Jun 17 2021, 1:15 PM
llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
8

The goal of this pass is to fast path the handling of sane inputs that aren't an error condition and fall back to libcall to get errno updated if we detect a bad input.

kpn accepted this revision.Jun 17 2021, 1:28 PM

Ah, errno. That was the missing piece. Got it.

LGTM

This revision is now accepted and ready to land.Jun 17 2021, 1:28 PM
This revision was landed with ongoing or failed builds.Jun 17 2021, 2:15 PM
This revision was automatically updated to reflect the committed changes.