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

    <tr>
        <th>Summary</th>
        <td>
            Wrong folding a binary operator into PHI
        </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/d3f70db51cbc0876937d404e96fbda04df793bd4/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2023-L2035

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

```llvm
----------------------------------------
define i64 @constant_range_and_undef2.2(i1 %c1, i1 %c2, i64 %a) {
entry:
  br i1 %c1, label %bb1, label %bb2

bb2:
  %v2 = and i64 %a, 4294967295
  br label %bb3

bb1:
  br label %bb3

bb3:
 %p = phi i64 [ poison, %bb1 ], [ %v2, %bb2 ]
  br i1 %c2, label %bb4, label %bb5

bb4:
  br label %bb6

bb5:
  br label %bb6

bb6:
  %p2 = phi i64 [ %p, %bb4 ], [ undef, %bb5 ]
  %res = and i64 %p2, 255
  ret i64 %res
}
=>
define i64 @constant_range_and_undef2.2(i1 %c1, i1 %c2, i64 %a) {
entry:
  br i1 %c1, label %bb1, label %bb2

bb2:
  %#0 = and i64 %a, 255
  br label %bb3

bb1:
  br label %bb3

bb3:
  %p = phi i64 [ poison, %bb1 ], [ %#0, %bb2 ]
  br i1 %c2, label %bb4, label %bb5

bb4:
  br label %bb6

bb5:
  br label %bb6

bb6:
  ret i64 %p
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i1 %c1 = #x1 (1)
i1 %c2 = #x0 (0)
i64 %a = #x0000000000000000 (0)

Source:
  >> Jump to %bb1
  >> Jump to %bb3
i64 %p = poison
  >> Jump to %bb5
  >> Jump to %bb6
i64 %p2 = #x0000000000000000 (0)        [based on undef value]
i64 %res = #x0000000000000000 (0)

Target:
  >> Jump to %bb1
  >> Jump to %bb3
i64 %p = poison
  >> Jump to %bb5
  >> Jump to %bb6
Source value: #x0000000000000000 (0)
Target value: poison

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/eJzUVltv4zYT_TXjFyIGNRR1edBDbsbuhwW-Il2gjwElUjYDmRRIyt301xe6WJa8TZot-tAVAkXDGc6cQx4PRniv90apAvgd8IeN6MLBuqK0Zv_SmZdNaeVrcQih9cBuAXeAu70Oh67cVvYIuGua0_nfTevsi6oC4K5sbAm4k6xOqSx5VJUVzdIkZ6mMaazypC6loLGs05yVMl7k0f2-r04YX1t39IC7z8aHe3sstVGT5boqaGvGRW3226ptAdkXpMhuviBlHOgD0Nvxfdvok0LiVGtdAHZL1mzE4N729bfW7QF3VV_nD8BdKHefKrbMBQkd_wa4w9LNB58xWqpaG0V0EhOIaWWND8KEZyfMXj0LI587I1WNWwTMdEQAeRUB3pPpG4fvfjNyAZgTSO_GxMoE99qTGixCSkeW-xtRqqY3y_LaxiXB3rwkAeQnJMAeiDByUfeexJjHeZJizhcFF0nZOmm0RvZ2ILsEAvJ2qN0e9Fib35HWam9Nj2DkQoA_DBa_G9HOLhxc350GXrGPr2y-xhO_CTxZB_KPBibr823xO4796kwjXjIcxDG7-JIhIHfKX99VO9BFPt-SU-Hsc8pPyNIpC7AHYI8_qVABGf1LqS7Y_-sa_Uci7ZH-VDJdiKa9kszcqUXfkYm0yhvANJCTcrp-BYyWaR-fnv7_1Lfgr8Lt-6SeHK1T04HZzpNwEIZ427lKrTZ-E8e2UTOms2KGowdk33o7iwDzlR9nP-399OKf9HHxXz3r8PH96whrcfnsEdgj-V93bEmwZ9G-42Sr6pNwRrG8s4u_50zWKfEDjHLgd6XwShJrxpZCTqLp1CzES4P4ofMZL_W_eT7j3U082e0HOE0SnXcsc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