[all-commits] [llvm/llvm-project] 494297: [RISCV] Add lowering for scalar fmaximum/fminimum.

Craig Topper via All-commits all-commits at lists.llvm.org
Mon Jul 24 13:47:00 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 49429783b0f4fb9c6f2a25746fe90072e19eb38c
      https://github.com/llvm/llvm-project/commit/49429783b0f4fb9c6f2a25746fe90072e19eb38c
  Author: Craig Topper <craig.topper at sifive.com>
  Date:   2023-07-24 (Mon, 24 Jul 2023)

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

  Log Message:
  -----------
  [RISCV] Add lowering for scalar fmaximum/fminimum.

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 lowering 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.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D156069




More information about the All-commits mailing list