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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization: (x & -2^C) -1 & -2^C + 2^C -> x & -2^C
        </td>
    </tr>

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

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

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

<pre>
    ```
define i32 @src(i32 %0) {
  %v0 = and i32 %0, -4
  %v1 = add i32 %v0, -1
  %v2 = and i32 %v1, -4
  %v3 = add nuw i32 %v2, 4
  ret i32 %v3
}

define i32 @tgt(i32 %0) {
  %v0 = and i32 %0, -4
  ret i32 %v0
}
```

alive2: https://alive2.llvm.org/ce/z/PVar64
godbolt: https://godbolt.org/z/h65Kneqzh

Found this pattern in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/opencv/optimized/t1.ll
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyckk2PmzwQxz_NcLESDWNMyIFD9sWXR4_UU-_G9ga3jp1iw-7m01eQlI22VQ-VEPLM_Obtr1EpuWOwtgXxAOKpUGPu49Be3rIoumjeW6jx9uHB2BcXLHOcGFSYBg3ULAYJBNoz2D0AHthsT8iAPzEVDPsgHtmmWoHyCpgVmK5EuRL0ucRUfqrB1xphfF0pmqkrNNi8ujngAXZP8__zKvmY_3WV-w740eFONcCD8m6yBPzA-pzPCfgBSALJq3_r_XTaxuEIJLUFkhcg-eWrGuq5xTGaLvr8e_ItcEucc_pa_Bfsj0t_7SrjGAzLvUvsrHK2Q2Au_KGOy_3YbXU8AUmT9dvl_RVIzkNt4jlvOht0f1LDdyDZ-dgByZNyYbbmCJCMZxv0tDyyO7mLNUAyl1vvC9Nys-d7Vdi23ImqbvZIWPRtZUzdvAjDubIVN_VOoLB1V_KXxtRCY-FaQhLYYEMl3yFua41G6J0uEUvdGAsV2pNyflWvcCmNti0FNVgVXnXWp-WsiYJ9ZUsUiOYrH9plu248JqjQu5TTR5nssrft_y4la9htI5VdXKQDat4YUM02BOL5cT6VTXnnYEAP7PraAH9m93AxDr79i_bzBL-EPw_xm9UZSC5zJyB5W2xq6WcAAAD__wu3C0Y">