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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Wrong negation of vector selection with a poison value
        </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/9a7519fdb39f21a807189e1ed06826b43db929e1/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp#L327-L350


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


```llvm
----------------------------------------
define <2 x i32> @negate_select_of_negation_poison.2(<2 x i1> %c, <2 x i32> %x) {
#0:
  %#1 = srem <2 x i32> { poison, 0 }, %x
  %neg = sub nsw <2 x i32> %#1, %x
  %sel = select <2 x i1> %c, <2 x i32> %neg, <2 x i32> %x
 %neg2 = sub <2 x i32> %x, %sel
  ret <2 x i32> %neg2
}
=>
define <2 x i32> @negate_select_of_negation_poison.2(<2 x i1> %c, <2 x i32> %x) {
#0:
  %neg = sub nsw <2 x i32> { 0, 0 }, %x
  %#1 = select <2 x i1> %c, <2 x i32> %x, <2 x i32> %neg
  %neg2 = add <2 x i32> %#1, %x
 ret <2 x i32> %neg2
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
<2 x i1> %c = < #x0 (0), #x0 (0) >
<2 x i32> %x = < #x80000000 (2147483648, -2147483648), #x0000000d (13) >

Source:
<2 x i32> %#1 = < poison, #x00000000 (0) >
<2 x i32> %neg = < poison, #xfffffff3 (4294967283, -13) >
<2 x i32> %sel = < #x80000000 (2147483648, -2147483648), #x0000000d (13) >
<2 x i32> %neg2 = < #x00000000 (0), #x00000000 (0) >

Target:
<2 x i32> %neg = < poison, #xfffffff3 (4294967283, -13) >
<2 x i32> %#1 = < poison, #xfffffff3 (4294967283, -13) >
<2 x i32> %neg2 = < poison, #x00000000 (0) >
Source value: < #x00000000 (0), #x00000000 (0) >
Target value: < poison, #x00000000 (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/eJzMVl1r6zgQ_TXKi0iQRv588EPbNNyFyy50L-xjke2xo-JYWUlO0_31i2znw0nbzeVSWFHcWNKcmXNmJI-0VtUtYkbCexIuZ7Jza22yXLf1S9e-zHJdvmVr57aWiDsCKwKrWrl1ly8KvSGwaprd4d98a_QLFo7AKm90TmCVyjjkaVXmIq2Ay4TFPEmRY8miBKI8EGWeQor8DEd5ux9GtrbSZmMJrH5rrXvQm1y1OH37HWvptFkU2y0B8V1APP8uQkbYkrC78-ddo3YI1OBWG0fEHZ3ykf3ywkew0KYmsCq8p38IrFz57Vv39zUiidjw14fdT81vHMPuEivVIiXiAeieKgFEPFISsNZzwmeLDRbuWVfP_YTS7fNWK6vbBRBIDla8N4KwIPBwCQXhnkBKSXw_RgyCecb9C_XrBASnRCypNbi5NI_v6eDQQzNK4mXvw6OeEFqsB4Aup619vQ7Bu3jHzmIz2PUs6W10Wqw_oDkAD1vgGNB7ejyM3g-xGHTvOoJRs3g5_hBLIh7_N5n7D93je8o-S9sp8T-j__7DrEwCGxIgy_Kmarg1AccLoVeUlhptSyB2dIdGVW8E-PnpfHx6-uPJn_Mf0tToqLJ0ow2OFa07S91attTqzhQ4MdzLzbbBo9pXyvTkiPAcxJ5RAgkjkA6kzibosVquZZxAJGwY3hB4EAeJiILE483PX08ehlH6_VxMPfXPPwdOlwQmOThGcDrhZ9i3kDgU4DVINQzhQQJIgzSKIRE9oct4L0EPt8JXaPNeiU1zeUH-BlGGwuwr7GO9v0SpT5L4C6gTTW4tjaHe6E42na-6X9BzPKsTpJsLdIil22ykeTu7KxkttDH-jnOTC8SOGzhV7ec7KKOVVA2Wc6d9f7PDjzeObQYao4296BNmZSbKVKRyhhmPBYMogCiarbMwSmQsoyqRCY8xLVjASgEgORcISVXNVAYMAs4EY0EYB9ECI5kEkOc8EXkZxhUJGG6kao4NzExZ22HGecATPmtkjo3t2zuAFl9pv0oAfLdnsr5xy7vakoA1yjp7gnHKNX1feN6BhUv6l9FtTQ-fN6orusPCaTN-T_zcq3JrKsf8DTmddab5-UayD9Z3gSObXQb_BgAA__9Gwc38">