[llvm] [MIPS] Implement llvm.fminimum and llvm.fmaximum with f32/f64 (PR #89907)
Cinhi Young via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 20:20:12 PDT 2024
Cyanoxygen wrote:
> > Can you have consider it?
> > It's due to that we process the most cases as early as possible.
>
> preliminary checks are essential since we do not know what value actually is in the operands, and since minnum and maxnum returns other operand if NaN exists, we have to check if there's any NaN in them.
>
> I have a “slightly better” version in mind, which might handle the edge case. Again, preliminary checks are essential:
>
> ```
> newx = max(x, y)
> if (newx == x) {
> if (y == NaN) {
> return y;
> } else {
> if (y == 0) {
> if (x == -0) {
> return y;
> } else {
> return x;
> }
> } else {
> return x;
> }
> }
> } else {
> return y;
> }
> ```
>
> Which roughly translates to:
>
> ```
> (SELECT
> (SETCC NewX X SETUEQ)
> (SELECT
> (SETCC Y Y SETUO) ; Y == NaN then return Y
> Y
> (SELECT
> (SETCC Y 0 SETEQ)
> (SELECT
> (SETCC X NegZero)
> Y X)
> X)
> X)
> )
> Y)
> ```
I just discovered that the logic above has a loophole. If X is a NaN, and Y is a real number, then the real number will be returned.
As this gets way complicated to implement, I would like to keep the original implementation. But we can handle this specifically for R6.
https://github.com/llvm/llvm-project/pull/89907
More information about the llvm-commits
mailing list