<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87072>87072</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            map `llvm.maxnum` to `NMax` instead of `FMax` and `llvm.minnum` to `NMin` instead of `FMin`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          farzonl
      </td>
    </tr>
</table>

<pre>
    FMax (Floating-Point Maximum):
- Result is y if x < y.
- If both x and y are zeros, either x or y is the result.
- If one operand is NaN (Not a Number), the result is the - other operand (the non-NaN operand).
- If both operands are NaN, the result is undefined.

NMax (NaN-Aware Maximum):
- Result is y if x < y.
- If both x and y are zeros, either x or y is the result.
- If one operand is NaN, the other operand is the result.
- If both operands are NaN, the result is NaN.
```
FMax is undefined if one of the operands in NaN, so in DXC we use NMax to match HLSL max. It looks like that matches the LLVM instrinsic semantics, so I think this will be a straightforward SPIR-V backend change, but we do have to check that it doesn't break anything for the OpenCL side. 
```
_Originally posted by @sudonatalie in https://github.com/llvm/llvm-project/pull/86844#discussion_r1543515572_

This issue is to track the work to `SPIRVInstructionSelector.cpp` and make sure changing the `TargetOpcode` to `GL::FMin` `GL::FMax` doesn't break OpenCL.
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L433C1-L438C67

I suspect we will be able to change
```c++
...
selectExtInst(ResVReg, ResType, I, CL::fmin, GL::FMin);
...
selectExtInst(ResVReg, ResType, I, CL::fmax, GL::FMax);
```
to
```c++
...
selectExtInst(ResVReg, ResType, I, CL::fmin, GL::NMin);
...
selectExtInst(ResVReg, ResType, I, CL::fmax, GL::NMax);
``` 
without effecting openCL.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVl9v47YT_DT0y8KGTMn_HvyQ8_38qwFH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