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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] `!(A & INT_MIN) && A & INT_MAX` is not fold to signed comparison with zero
        </td>
    </tr>

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

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

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

<pre>
    https://godbolt.org/z/rxPnbEnoT

```c
void fn();

void test(unsigned *d) {
    int is_negative = *d & 0x80000000;
    
    if (!is_negative && *d & 0x7fffffff) {
 fn();
    }
}
```

GCC recognizes this pattern and folds it to comparison 

```asm
test:
        mov     eax, DWORD PTR [rdi]
        test    eax, eax
        jg      .L4
 ret
.L4:
        xor     eax, eax
        jmp fn
```

However, LLVM 18 main fails to optimize it:

```asm
test:
        mov     eax, dword ptr [rdi]
 test    eax, eax
        js      .LBB0_2
        and     eax, 2147483647
        je      .LBB0_2
        xor     eax, eax
 jmp     fn@PLT
.LBB0_2:
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVF1v4joQ_TWTl1GRM_nkIQ9ALvdWor1VhXb3rUqIA64SG9nmY_n1KyeUBrrtPqyFGOOZOZ5zzExhjFhLzjOIphDlXrGzG6WzQlveeqWqfmYba7cGggnQHGi-VlWpGjtSeg00PwHN9fFJlv9ItQSWA5ucv2PWf1b9770SFdYSKAUaQzAdxnY-y40FSneyK6dCoEkFNEZIzrGIiEJaFOZF8nVhxZ4jBHkXiEAxsmPK-nXBdzmD7Bq7-_0rCIpd8gAlqft1ffuH2jvsJD8TuWzeeA8J_juboeYrtZbixA3ajTC4LazlWmIhK6xVUxkUFq3ClWq3hRZGSfytnoVp-5NOsGDyXoxbrdp3lhdHoBnm3_9_zvFp-YwQTXUlIMqv4x3IIN6ZK__rurejRXh2aG77nTu6vf6oNH4J126dkJ8r9Z868D3XLnmx-PaAfoptISTWhWiMk0dtrWjFiaN4J_83ClUHpSvcWv1BoT9KY96kmU7ZC1073asOkskPkzAN4jC5weBfYHwqplPRrVpCyJ4Wy7f36DFuCV8e7CKQV2VBNQ7GhcczPx4nIWM-Rd4mi3gUFH6dpFFah0FZU1qVfhkmLC1rFoUrT2TEKPCZHxFjxKJRFVEcpWmd-Dzxq5BByHhbiGbUNPvWzQhPGLPjWTz2KfCaouSN6SYNkeQH7JxA5AaPzlzOXblbGwhZI4w17yhW2KYbUffS2JlqSyE5RDk6QuQDpZOuee8fly8P949d5_Z9PTif_ICYoTAole1azv2fztNm0HUHYTd44lp5O93cDj9hN7tytFIt0NwVdzZ3W61e-coCzTtKBmjeUf4VAAD__-gscUU">