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

    <tr>
        <th>Summary</th>
        <td>
            WebAssembly: Suboptimal "promotion" of wasm_f32x4_convert_i32x4 into f32x4.convert_i32x4_u
        </td>
    </tr>

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

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

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

<pre>
    When wasm_f32x4_convert_i32x4 intrinsic gets its input from an instruction that clears top bits, the conversion gets compiled into i32x4_u instead of i32x4_s variant; for example:

```c++
v128_t plsno(v128_t x)
{
    // u32x4 here changes the convert instruction; it's a problem because u32->f32 is way slower on pre-AVX512 HW
    x = wasm_u32x4_shr(x, 1);
    return wasm_f32x4_convert_i32x4(x);
}
```

```
        local.get       0
 i32.const       1
        i32x4.shr_u
        f32x4.convert_i32x4_u
 end_function
```

This is a problem because on x64 hardware, `convert_i32x4_u` gets lowered into a long multi instruction sequence unless the browser implements AVX512 code path and the hardware supports it. Thus this needlessly slows down efficient SIMD kernels.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VE2TozYQ_TXi0jUUNNjYBw7eTFzJIafdyuTmEqIxSoRE1JLtya9PCZiKdzeJSy5KUuv169cfkllfLVErdp_E7jWTMYzOt39RfGSd69_bt5Es3CVPl6HCR31Rzt7Ih4tOO9A2eG1ZK7hSYNDpb-cYYPBuAmlBWw4-qqCdhTDKAMqQ9AzBzdDpwAJ_gDASrLCczBYk5aZZG-qTBweLs0tc0Ej24IbtiOEmvZY2iOoTDM4DPeQ0GxLVSRTL2hfrUgI_pVWcbiUeLgFmw9YJPGzbh8Bjsm-SCQCAwLPAM8QlzpE8gRqlvRI_8Q3P8SUKOghsGCTM3nWGJuhIyciUYF5E9eNQIWiGu3wHNu5OHpyF2dPL6dffdiXCT2-b9weI6nXVPa6Rjl7g4ZH0KhPV6oOnpxD9f6dofbTZi-b1WZNvJNoA0884JU1-pbDtlztdYa6c5Y_D8unB4ivn0V_i0-nCJ_-Kz3pPtr8M0a66fcfoy6g5yfS9jM7CY1_DKH1_l56SGim33zjYF2sRLQp_1JAE4-wVpmiC_qosmf6MZBVBtIZ4TW_n3Z3Jg07FNJENDFuGlOsJZhlGkLZfbD_IAMd5dn5pgxy-jDFBaQZL1Cdgs-acoXd3CzQMWmmyAT7__Msr_EHekuE869uqP1ZHmVFbNjs8lE3V7LOxpUphV0iqi-NRlgUdccB9Vx_7XuJe7etMt1jgrmjKQ7GrcbfPC6zrsikVlbLr6qEXdUGT1CY35jblzl8zzRypLetjvWsyIzsyvMwBREt3WG4FYhoLvk2PXrp4ZVEXRnPgf2CCDobaN-pOzDR15l1UJ_gcOzcHPUkDAnH2bnJLshFT9_7fQHH_XjZZ9KYdQ5g5NffSnFcdxtjlyk0Cz4nO9nmZvfudVBB4XoJggectyluLfwcAAP__S_iV7w">