[PATCH] D156069: [RISCV] Add lowering for scalar fmaximum/fminimum.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 23 19:01:20 PDT 2023


craig.topper created this revision.
craig.topper added reviewers: asb, reames, kito-cheng, fakepaper56, wangpc.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: eopXD, MaskRay.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156069

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInstrInfoD.td
  llvm/lib/Target/RISCV/RISCVInstrInfoF.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/test/Analysis/CostModel/RISCV/fp-min-max-abs.ll
  llvm/test/CodeGen/RISCV/double-maximum-minimum.ll
  llvm/test/CodeGen/RISCV/float-maximum-minimum.ll
  llvm/test/CodeGen/RISCV/half-maximum-minimum.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156069.543345.patch
Type: text/x-patch
Size: 31340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/6020dabb/attachment.bin>


More information about the llvm-commits mailing list