[PATCH] D123972: [RISCV] Add isCommutable to FADD/FMUL/FMIN/FMAX/FEQ.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 19:56:00 PDT 2022


craig.topper added a comment.

In D123972#3487252 <https://reviews.llvm.org/D123972#3487252>, @arcbbb wrote:

> As mentioned in spec, `For the purposes of these instructions only, the value −0.0 is considered to be less than the value +0.0`
> I think FMIN & FMAX is commutative.
> LGTM.

For some additional detail.

In C++, std::max of 2 FP numbers is not commutable but std::fmax is commutable. std::max is implemented as something like `a > b ? a : b` which returns `b` when `a` or `b` is a nan since relative comparisons return false if either input is a nan. std::fmax on the other hand returns the non-nan input unless both inputs are nan.

RISCV's implementation of FMAX/FMIN is similar to std::fmax (though there is a difference for snan). X86 SSE on the other hand implement FP max/min instructions that are closer to std::max. For X86, we allowed max/min to be commuted under fast math using CodeGenOnly instructions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123972/new/

https://reviews.llvm.org/D123972



More information about the llvm-commits mailing list