This is an archive of the discontinued LLVM Phabricator instance.

[LibCallsShrinkWrap] Set IsFPConstrained is true for creating quiet floating comparision if function has strictfp attribute
ClosedPublic

Authored by Jim on Jun 12 2023, 10:17 PM.

Details

Summary

Create a quiet floating-point comparision if function has strictfp attribute.
Avoid unexpected FP exception raised during libcall domain error checking.
It raises an FP exception only in case where an input is a signaling NaN.

Diff Detail

Event Timeline

Jim created this revision.Jun 12 2023, 10:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 10:17 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Jim requested review of this revision.Jun 12 2023, 10:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 10:17 PM

FP exceptions aren't supposed to matter in the default FP environment. This will create extra code on RISC-V that doesn't have quiet comparisons.

We shouldn't be generating calls to constrained FP functions unless we're in a function marked strictfp. And we don't care about exceptions outside such functions.

Do we actually run this code for strictfp functions? If we do, I guess we need to adjust it, but we need testcases.

Jim added a comment.Jun 13 2023, 6:53 PM

The testcase look like

volatile double d;
d = __builtin_nan ("");
feclearexcept (FE_ALL_EXCEPT);
acos(d)
if (fetestexcept (FE_ALL_EXCEPT))  // expect no fp exception raised
  abort();

acos(d) emits extra two floating comparision that raise fp exception when a input is quiet NaN.

Something like https://godbolt.org/z/Yn31Tfoc4 ?

You need to add a check along the lines of if (BBBuilder.GetInsertBlock()->getParent()->hasFnAttribute(Attribute::StrictFP)) so this doesn't affect functions that aren't marked strictfp. Or maybe we should just disable the whole pass if the function is StrictFP?

Jim updated this revision to Diff 536940.Jul 3 2023, 8:17 PM

Only set IsFPConstrained is true if function with attribute strictfp.
Also add testcase from my example program.

Jim retitled this revision from [LibCallsShrinkWrap] Set IsFPConstrained is true for creating quiet floating comparision to [LibCallsShrinkWrap] Set IsFPConstrained is true for creating quiet floating comparision if function has strictfp attribute.Jul 3 2023, 8:19 PM
Jim edited the summary of this revision. (Show Details)
efriedma accepted this revision.Jul 5 2023, 2:19 PM

LGTM

This revision is now accepted and ready to land.Jul 5 2023, 2:19 PM
This revision was landed with ongoing or failed builds.Jul 5 2023, 10:29 PM
This revision was automatically updated to reflect the committed changes.