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

    <tr>
        <th>Summary</th>
        <td>
            missed optimisation combining >= while > is ok?
        </td>
    </tr>

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

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

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

<pre>
    Exhibited in rust when doing some parsing: https://rust.godbolt.org/z/xv1WjY55o 
- top is good, the cmp's are combined, I use >
- bottom is bad, cmp's are not combined, I use >=

Someone had this to say about the issue (referencing https://godbolt.org/z/YW6b4fMeP which puts it in llvm ir terms):

> I think I see what's happening. The >= code is hitting InstCombinerImpl::foldICmpAddConstant, where it runs this transformation:
> ```
>   // X+C >u C2 -> (X & ~C2) != C
>   // iff C & C2 == 0
>   //       C2+1 is a power of 2
> ```

> which turns
> ```
>   %A = add i64 %val, -4
>   %B = icmp ugt i64 %A, 3

> =>
>   %0 = and i64 %val, -4
>   %B = icmp ne i64 %0, 4
> ```

> But this later impacts InstCombinerImpl::foldAndOrOfICmpsUsingRanges(), which can fold icmps that involve adds, but not ands. The > version of the code doesn't hit the first fold, so the add/icmp doesn't get turned into an and/icmp, meaning the second fold runs, which is what actually combines the two icmps into one 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2P2zYQ_TX0ZbCGRFmyfdDBq10DPhQp-oEkR0ocSUwkUuBQdraH_vZiKDtOt9u0MQxboN7MvDczfIrIdBaxFPmjyJ9Wag6986XSaiRc1U6_lM9felObgBqMBT9TgEuPFrQztgNyI8KkPBnbiewAfQgTiewg5FHII6PXndO1G8La-U7I4x9CHr-c0_efPua5A5E8ieTwAMFNYAg657SQFYQeoRknIbcEyiM0bqyNxfjuBDMhiOz5Flu7ENzI4bWKiG8jrQv_Ep09LQmW31_diM4i9EpD6A1BcEDqBV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