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

    <tr>
        <th>Summary</th>
        <td>
            Redundant zext.h following dominating comparison against zero
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V,
            performance
      </td>
    </tr>

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

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

<pre>
    This is a performance opportunity noted when analyzing sqlite3. Filing this with reproduction instructions for the original observation and some analysis below, plan to follow up with reduced test cases when I have some time.

`$clang -isystem $GNU_TOOLCHAIN_DIR/sysroot/usr/include/ --target=riscv64 -mllvm -riscv-v-vector-bits-min=256 -mllvm -scalable-vectorization=on -Xclang -target-feature -Xclang +v,+f,+m,+c,+d,+zba sqlite-autoconf-3380500/sqlite3.c -c -O2 -g`

The amalgamation file is taken from the sqlite3 website.

Non optimal assembly observed:
```
        lw      a0, 8(s5)
        blez    a0, .LBB831_105
        zext.w  t1, a0
```
In this case, the zext.w is a nop.  lw is sign extending, and the immediate prior branch is taken if a0 <= 0.  Given that, the high 32 bits of a0 must be zero already.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtVE1v2zAM_TXOhbChyrGXHHxYW3QLMLRA1w27FZJN29pkyZPkZMmvH2V7WQcMEUx9UI8U32Okbc7VS6880BAwomutG4SpEew4Whcmo8IZjA3YwKlHA8IIfb4o04H_qVXAPIMHpeM6RJiTCj04HJ1tpjooa0AZH9wy90Do5EfgTnWKkMBKj-4oZk9hGvB2wCWGJzSJ2p4SfgejFgaCpfuadmAa_wSiKJRZQB-gFh79kuQBenHEBSyoAbOE3Sfs_fotWcK3NSF2kCp_9gEHoJ0Pj19eX56ePt19fH94fL0_PCf8gU6dtYFmk3f0VabWU4M0gzQNwnUYkvzeKV8fyy2kg9bHAdJ5ndIP62BdKlXw6aAMefKivHr5WmghNa5u6jJXgZyoFOm3Nb8lRtqiCJPD637Cb49UFzLtYobF1ItpFnORYmUpFVOwtTVtmuc7VjAW37byV0NK44lD2sXSvKnUCzElBqE7-swMtUpjVEoQP6jKrbPDzOaKBCeUnib_VPuRrtmRSCCyhfc4SH1eWccmyd9wsoz16l6f6CNYJH-X8J0vEr6_HlLVLtfj7NPt7S6_eb1hxdXhgr9CFhHCTXQR7L9hDmYRbVROdItvWW4u7WDsmAHoeeVVZ4DO0DQk9hmU5BpvqGHARomAMDpF-paO-qf_WybVUnxI8juiFhgBflBHjJFF-BO0V10POYeoFLCz_zCRpGXMx1kQ2qFoztmmqfJmn-_FJqigsXom_ZtGmLCk3a_9EbuxsaQ4Yo2mtR1GQZqMLdaJ2I8z6mZyuupDGH2kgT_Q6KipJpnRBVpEla4mpX7-TiqNHeD9hJ4mRZlztumrXV2yst3hO77dizrfbmXDsX7Xsp3YN3kpNiRy1L5KituEcylqqkkk_vnw-S79SluxCGTe_PfEzeJ-oyrOOGdlzjgr-JZlZSvbvdwR2TdS8qZItgwHoXQWc8ys6zaumtOVU-fpUCsf_N9Dkh-RiDinQvjUE7111Ui1HdBv5pdV87N-A2rvpnI">