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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Failure to merge similar comparisons that share a common true/false condition
        </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>
          RKSimon
      </td>
    </tr>
</table>

<pre>
    Noticed while looking at the 'IsBigEndian' checks in D138872
```
bool src(bool c, int x) {
  if ((c && x == 15) || (!c && x == 0))
    return true;
  return false;
}
bool tgt(bool c, int x) {
  if (x == (c ? 15 : 0))
    return true;
  return false;
}
```
https://godbolt.org/z/eEbqfsGM1
https://godbolt.org/z/f96znedee (General Case)
```
----------------------------------------
define i1 @src(i1 %c, i32 %x) {
  %cmp = icmp eq i32 %x, 15
  %or.cond = and i1 %cmp, %c
  %cmp3 = icmp ne i32 %x, 0
  %or = or i1 %cmp3, %c
  %or.cond7 = xor i1 %or.cond, %or
  %not.or.cond7 = xor i1 %or.cond7, 1
  ret i1 %not.or.cond7
}
=>
define i1 @tgt(i1 %c, i32 %x) {
  %cond = select i1 %c, i32 15, i32 0
  %cmp = icmp eq i32 %cond, %x
  ret i1 %cmp
}
Transformation seems to be correct!
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVE1z2yAQ_TXowsQjIevroENix5lMpz20_QNIrCQaJBxArZtf30VSbMfJtD7Usx4WeLzdfSyqtPhdftFO1iDor04qoErrJzm0lDvqOqCEZY_2Trb3g5B8wBmtO6ifLJUD3UZxnmeMhFsS3pI0XGyaVlorak1NWD656GzwjKMHwgpKsrsZRqlsMEaOVuOYotEDJfEWjUbJjN2gzaDoPShEjLeFjlIDbjQDdWYEEh_DLKsNV_a0TLLtWbaudVdmeww-px3vMFUcbv9PMhdKds7tLZITtkNrtai0cittWpy94B_uq-fGPnyOroM3RfoygAB_tfkDDGC4ohuOibzmfRH_5srfjBbQyAGojChZh_P9e58ls6Qx8_6lqn6733tRqfQOPJ8hN74PTkBtVrUexATmOC7s_d4jpzhvSOMTq0_rjDV8QzrBcDjSxR_wLbGzCXw4opfl5YA2ZycG7bX_26lsqvCsM5bt85OXDeKb7_4DvecOvk7vVw0tKKhfgx4P-ac3e-G_L-ms-MP7QvzVvM3_u-GDbbTpuZN6wAygt9RpWgGttTGYDr70i14MoIzStMjDPCvWgShjUcQFD5x0CkqS3D0O1m10X6EYJNnSHZdqNOBZezAtUCt7qbjBAP2eG2n1gCE7_MjZjiOO-41eLy8VX4l_mtQXJn2OwWhUefGypOvGCu-nx4lSP1-Hm73RP6YSdtLaESw6ScHSNOhKCHORVU20hqIOeZ3neZxWSSOqJokywfNA8QqU9fUQxibS-FZiZfVSGWOzzqxHbhA3eu-wrpdJR7-ZbANZspCxKIrDKFqnLF2JLBOJYDzK8lRkcY19Aj3Ks_L8_sMQmHJKvBpbi5tKWmdPm9xa2Q4wiez5-eg6bcqvn75J1CuYaiynAv8AEqfAXg">