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

    <tr>
        <th>Summary</th>
        <td>
            Missed combination of sub+and
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    I've found a case of `sub+and+sub` which can be combined into single `and`.

```llvm
define i64 @src(i64 %0) {
  %2 = sub nuw i64 71, %0
  %3 = and i64 %2, -8
  %4 = sub i64 64, %3
  ret i64 %4
}

define i64 @tgt(i64 %0) {
  %2 = and i64 %0, 120
  ret i64 %2
}
```
https://alive2.llvm.org/ce/z/MrCTxL
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNUduO2yAQ_Rr8gmLhwfjywEOy0UqVum_9ATBjm8qXyOBsu19fjJNstupDpTEG5syZwxw9m9_yG4HyirSd18lQRRvlkM4tJQVzqyZwUpMJ67YvGH3vbdMHzEQ10mYetZ3QUDv5mTo7dQNudVtFwVLCzoQdb2vB9hiG67hfGWxDMbVFTknO3NIQqOIBBCNQU1KediDdroASfqZBBZ3W91hUZgRedvQnjEdYEEBvVLCBDtUTJH8wbZAiv7HwO2RBfy_Ob-LL8_Nbvgr3nf8P4U-K2NYwA_aPfvB3v_vU9mPv_cURfiTwGkIN9oqQbgNN56ULNw2G5SN8b8vLj1_fE5RZURQ854UoEyO5qXmtEm_9gPLNOhec2y1U3s7TZvrD8WRdBvm1X2d9v-o0VIRDtHH_HS7L_BObMIXXwLmiCxtRCeBJL0E3wGtRMcOMNlg1kNV1i7oRaOpWiGRQGgcniTgRgEjKj_PF29F-RFGBDHaDYIyKD8_ZLSnOiZXAADIWos7yrEw5thwNUxnLGWojgk04Kjs8hpUsMkrXa-dCcrDOu8-kcs52E2KUFfjV6vt5kU3fKueT-EgZX_gHkpXq5Q">