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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missed optimization: `((A - 1) & (~A)) >> 63`  --> `A == 0`
        </td>
    </tr>

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

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

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

<pre>
    Alive2 proof: https://alive2.llvm.org/ce/z/9fa--y
## Motivating example

```llvm
define i32 @src(i64 %3) #0 {
  %4 = add i64 %3, -1
  %5 = xor i64 %3, -1
  %not.i.i20 = and i64 %4, %5
  %shr.i.i21 = lshr i64 %not.i.i20, 63
  %6 = trunc i64 %shr.i.i21 to i32
  ret i32 %6
}

define i32 @tgt(i64 %3) #0 {
  %4 = icmp eq i64 %3, 0
 %5 = zext i1 %4 to i32
  ret i32 %5
}

```

It's a specific pattern found in https://github.com/openssl/openssl/blob/2a6305dfcd89632b69e49f8b3efe98b7e0daa1aa/crypto/ec/ecp_nistz256.c#L793
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMk0GPozgQhX9NcbGITBkbOHCgk0Zqafu-t5UNJvEKMItN1Mlhf_vIkE4no-nRSJET21-92M-vpHPmOGpdAn8Bfojk4k92Lv_eny6Rsu2lrHpz1kim2doOWEVO3k8OWAVYA9Zy3d31_XnY2fkIWDcasL4C1kUn4_gC9AC0AmSAjLxbb87Sm_FI9Iccpl7ftrdR0O0T1LalVndm1MQwJJBSNzeAuREpAeQMsCCAjBLIXjaahPWUADsQ2bbkC9yTOHlA-Ip82Pl7ZLR-Z3YG6aY23tXSgAaNB9id5hVOVrh3p7vwXSZUCfZQI1bWz8vYfMJfMt6GK3_Ss_abA8jFzans8Gjcs0v-6P_UJdMME9H_PdlAb9Tdp6v-8MQkW9W3J-O_PNn9SR8X3zxg5ogkbtKN6UxDJum9nkfS2SU4Pf4UsqPxp0XtGjsA1nbSo3P90y_VWwVYoxSM8rZr2rwQDJUodFp0uWK600WuMk1bKRMpQ0rny-QtYK2bdZj-GY3zV-Ri1wCyv7KCRW3J2oIVMtJlkiFPOTLBo1MpVE5pmydSCJmkKSqusMWs6SjXjdAqMiVSTGlB0wSTAtkuY60QnGnRdR1XCYeU6kGa_t43kXFu0WVCM8Q86qXSvVs7EnFtBlaZ0fnGDsqMGhAB94A4GOd0G9vJm8FcpTd2DHv8EM1lKIvVcnSQ0t44777-yxvfr_3-Njq_v2nyA3lf5ciTHKtIeD3MAfOKxCTZ8iQIYP5_BVisc_YK7DXkW1BC4jhMQIQMsUNIUAhAtMx9-ZtnXa-5fcXTbP_VjQesV1scYH1z5lzijwAAAP__A5FKIw">