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

    <tr>
        <th>Summary</th>
        <td>
            Wrong folding of `and` and `or` of `icmp`s
        </td>
    </tr>

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

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

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

<pre>
    https://github.com/llvm/llvm-project/blob/f52b89561f2d929c0c6f37fd818229fbcad3b26c/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L2738-L2746

Alive2 report: https://alive2.llvm.org/ce/z/Mk92Z5

```llvm
----------------------------------------
define i1 @bitwise_and_bitwise_and_icmps_comm3.2(i8 %x, i8 %y, i8 %z) {
#0:
 %c1 = icmp eq i8 %y, 42
  %x.m1 = and i8 %x, 1
  %#1 = and i8 %z, %x.m1
  %z.shift = shl i8 1, %#1
  %x.m2 = and i8 %x, %z.shift
  %c2 = icmp ne i8 %x.m1, 0
  %c3 = icmp ne i8 %x.m2, 0
  %and1 = and i1 %c2, %c1
  %and2 = and i1 %c3, %and1
  ret i1 %and2
}
=>
define i1 @bitwise_and_bitwise_and_icmps_comm3.2(i8 %x, i8 %y, i8 %z) {
#0:
  %c1 = icmp eq i8 %y, 42
  %x.m1 = and i8 %x, 1
  %#1 = and i8 %z, %x.m1
 %z.shift = shl nsw nuw i8 1, %#1
  %#2 = or i8 %z.shift, 1
  %#3 = and i8 %x, %#2
  %#4 = icmp eq i8 %#3, %#2
  %and2 = and i1 %#4, %c1
 ret i1 %and2
}
Transformation doesn't verify!

ERROR: Target's return value is more undefined

Example:
i8 %x = #x03 (3)
i8 %y = #x2a (42)
i8 %z = undef

Source:
i1 %c1 = #x1 (1)
i8 %x.m1 = #x01 (1)
i8 %#1 = #x00 (0)       [based on undef value]
i8 %z.shift = #x01 (1)
i8 %x.m2 = #x01 (1)
i1 %c2 = #x1 (1)
i1 %c3 = #x1 (1)
i1 %and1 = #x1 (1)
i1 %and2 = #x1 (1)

Target:
i1 %c1 = #x1 (1)
i8 %x.m1 = #x01 (1)
i8 %#1 = #x00 (0)
i8 %z.shift = #x01 (1)
i8 %#2 = #x01 (1)
i8 %#3 = #x01 (1)
i1 %#4 = #x0 (0)
i1 %and2 = #x0 (0)
Source value: #x1 (1)
Target value: #x0 (0)

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEls1u4zYQx59mfCFiUEN9HnRw4jVQYIsF0gVa9BJQImUzlUiXlJyPpy8oKYrslbPdy24Q2KLnx_8Mh6PBcOfUXkuZQ3QL0XbFu_ZgbF4YvX_s9OOqMOIlP7Tt0QHbAO4Ad3vVHrpiXZoGcFfXp7evm6M1j7JsAXdFbQrAXRVhkWZRHFQoMsxKWsYVSyqRBiliVhUlF6zAuJzpKL_vq-XaVcY2DnD3m3btnWkKpeX5aqPFF_uXsevyeARknzFh6c1nTMIY6BboZvjc1OokkVh5NLYFtiHnh-G9ee3dr43dA-5K7-YVcPf7Pxn-Hc21IKbDfx9t_9PN__wbaCErpSVRAYGQFqp9Uk4-cC0e5s-qbI7uoTRNw9YImKqUAEbPgHdkeHx5f3wFzAgkt2N8yKg_Wb_w5jIgwLbEKxL573x7iCPVa6-bAeRakJm7YMYAskvm1TPj9hn5unYHVbU97A61h4OR9CLnfnHJ77vIDC7x_Sw-h-nkGu8InYNsGcRLkGsxO1IwOBn9l8E5iJcgG0Ev8oZa2Y5mv2O8k2Q7PrAtsE-_oA5-SSEs1IF2T0R3Tx_UAyAb8mzsm_JYBt_GwK4Ujtc4J8OFo3uB5Q0Ld-01Lsviw6ue-hdvldFEGOk0YNKSk7SqegEM5l3l0_39l3vfmb5yu5ctYOK8fGc1OfG6k0Q50hgrSaeHuhFnu595c6zldN1jNvoj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