<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:cwabbott0@gmail.com" title="Connor Abbott <cwabbott0@gmail.com>"> <span class="fn">Connor Abbott</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - [AMDGPU] fneg optimized to xor with sign bit removed"
   href="https://bugs.llvm.org/show_bug.cgi?id=43711">bug 43711</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>RESOLVED
           </td>
           <td>REOPENED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>cwabbott0@gmail.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>INVALID
           </td>
           <td>---
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - [AMDGPU] fneg optimized to xor with sign bit removed"
   href="https://bugs.llvm.org/show_bug.cgi?id=43711#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - [AMDGPU] fneg optimized to xor with sign bit removed"
   href="https://bugs.llvm.org/show_bug.cgi?id=43711">bug 43711</a>
              from <span class="vcard"><a class="email" href="mailto:cwabbott0@gmail.com" title="Connor Abbott <cwabbott0@gmail.com>"> <span class="fn">Connor Abbott</span></a>
</span></b>
        <pre>nir_op_fneg in Mesa canonicalizes the result because that's what Vulkan
requires. Specifically VK_KHR_floating_point_controls requires that the SPIR-V
OpFNeg flushes denorms to 0 when flushing denorms is enabled for the shader.

We currently map nir_op_fneg to "fsub -0, x" using LLVMBuildFNeg(). This should
produce a canonical result, the same as if I say "fsub y, x" and y happens to
be -0, and be identical to a normal fneg otherwise except maybe with funky
rounding modes. In the past this was what Clang also did, even though C/C++'s
negate operator maps to the standard IEEE sign bit operation that you quoted,
so it was wrong, and only recently has there been a native FNeg instruction
added which does just sign bit fiddling (and I don't even know if Clang uses it
yet). Backends then detected "fsub -0, x" and turned it back into an xor
instruction, which fixes the original clang bug but introduces a new one for
things like "float x = -0, y = ...; return x - y;" This is still happening with
AMDGPU, and now that we're trying to support DX games where DX expects that you
consistently flush denorms when adding/subtracting, that's not great.

I'm not sure moving forward what the canonical way is for an LLVM frontend to
emit a negate that also canonicalizes, "fsub -0, x" or "canonicalize(fneg(x))".
But the current LLVM behavior where "fsub -0, x" gets remapped to "fneg(x)" is
definitely wrong.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>