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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL][DirectX] `firstbithigh` returns bit index from wrong side
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            HLSL
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          V-FEXrt
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/1ahzc64a8

DXC returns `32 - firstbit(S)hi` instead of directly returning `firstbit(S)hi` like clang currently does. This test confirms it is intentional https://github.com/microsoft/DirectXShaderCompiler/blob/b390fb19adc5d7c23180eb470470411fce986910/tools/clang/test/HLSLFileCheck/hlsl/intrinsics/bitwise/firstbitHi.hlsl#L10

Without the inversion the result has the bit set from the wrong direction.

This is a bug in the clang lowering that was caught by https://github.com/llvm/offload-test-suite/pull/210
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8U81u4zYQfhrqQtigKNGyDjpk4wp7yC1FmysljsTp0mTAGcXNPn1B2YsWi0UBAcQI_IYz348lwjUCDMJ8EeZS2Y19ysMfh_G3t8zVlNzn4JnfSTRPQo9Cj2tyUwp8THkVevwu9Fhb_30-tfYs1JNQT5e3Z5mBtxxJipNqtDzIBTPxhCz0-VXo3qM4KYmRGKyTaZEOM8wcPh9AjGuB_hIV8BvIOdi4ynnLGWKBuQR0lL97JMlALOcUF8xXksgSSWJkiIwp2iB_2gbZb9NxTlehxyvOOVFaWOjxsk_09uqtg_ycru8YIAs9TiFN5Wh6tUx1b91sXDfrpj4rmNpOla-ulxn686mvldAjpxRI6HGfudRA5YGvL68vIwZ49jB_E3r0gYLQI0bOGAnnApmQb0gg9PiDiq94vF9sXmp15_tPZJ82luxBYvyATJjiXmWgLbD0lvZyQpYELJecrvuPW05xfXCPKR7v_XYWkaSV07ZKvLe6Ex7SDXIRh71lebMkZ7utnuX0-X-8hvBRjrQsIVl3KAQcaEMui71voayta1W5oXF909sKhroz6ty1Xd1UfjDWdG4x9tzMbWPbBqbWGNM6bVTXO1NXOGiljTppU5-VqdVxAa1PoN3StD2cQItWwdViOJZJinMrJNpgqFvTGV0FO0GgPQJaF12E1iUMeSj3D9O2kmhVQGL6twMjhz02O8BchPny8Iwwl_-61-Pqi3F_ZKLIgNHB33ch7iIQOqi2HH4O2y9o3Gd6z-kvmIuP9k2KWR7LfAz6nwAAAP__UdxASQ">