This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add lowering for scalar fmaximum/fminimum.
ClosedPublic

Authored by craig.topper on Jul 23 2023, 7:01 PM.

Details

Summary

Unlike fmaxnum and fminnum, these operations propagate nan and
consider -0.0 to be less than +0.0.

Without Zfa, we don't have a single instruction for this. The
lowering I've used forces the other input to nan if one input
is a nan. If both inputs are nan, they get swapped. Then use
the fmax or fmin instruction.

New ISD nodes are needed because fmaxnum/fminnum to not define
the order of -0.0 and +0.0.

This loweing ensures the snans are quieted though that is probably not
required in default environment). Also ensures non-canonical nans
are canonicalized, though I'm also not sure that's needed.

Another option could be to use fmax/fmin and then overwrite the
result based on the inputs being nan, but I'm not sure we can do
that with any less code.

Future work will handle nonans FMF, and handling the case where
we can prove the input isn't nan.

This does fix the crash in #64022, but we need to do more work
to avoid scalarization.

Diff Detail

Unit TestsFailed

Event Timeline

craig.topper created this revision.Jul 23 2023, 7:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 7:01 PM
craig.topper requested review of this revision.Jul 23 2023, 7:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 7:01 PM
Herald added subscribers: eopXD, MaskRay. · View Herald Transcript
This revision is now accepted and ready to land.Jul 23 2023, 10:10 PM
This revision was landed with ongoing or failed builds.Jul 24 2023, 1:46 PM
This revision was automatically updated to reflect the committed changes.