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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] wrong folding of an extension and a binary operator for undefined inputs
        </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/a33fd61862efc03cfde2cc84c2a2d6f7f1c55983/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2336-L2346

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

```llvm
----------------------------------------
define i32 @test8_vec.3(i16 %V) {
#0:
  %ashr = ashr i16 %V, 8
  %sext = sext i16 %ashr to i32
  %#1 = sext i16 %ashr to i32
  %mul = mul i32 %sext, %#1
  ret i32 %mul
}
=>
define i32 @test8_vec.3(i16 %V) {
#0:
  %ashr = ashr i16 %V, 8
  %narrow = mul nsw i16 %ashr, %ashr
  %mul = zext nneg i16 %narrow to i32
  ret i32 %mul
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i16 %V = undef

Source:
i16 %ashr = #x0000 (0)  [based on undef value]
i32 %sext = #x00000000 (0)
i32 %#1 = #x00000000 (0)        [based on undef value]
i32 %mul = #x00000000 (0)

Target:
i16 %ashr = #x0018 (24)
i16 %narrow = #xf400 (62464, -3072)
i32 %mul = poison
Source value: #x00000000 (0)
Target value: poison


----------------------------------------
define <2 x i32> @test8_vec.2(<2 x i16> %V) {
#0:
  %ashr = ashr <2 x i16> %V, { 8, 8 }
  %sext = sext <2 x i16> %ashr to <2 x i32>
  %#1 = sext <2 x i16> %ashr to <2 x i32>
  %mul = mul <2 x i32> %sext, %#1
  ret <2 x i32> %mul
}
=>
define <2 x i32> @test8_vec.2(<2 x i16> %V) {
#0:
 %ashr = ashr <2 x i16> %V, { 8, 8 }
  %narrow = mul nsw <2 x i16> %ashr, %ashr
  %mul = zext nneg <2 x i16> %narrow to <2 x i32>
  ret <2 x i32> %mul
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
<2 x i16> %V = < #x0000 (0), undef >

Source:
<2 x i16> %ashr = < #x0000 (0), #x0000 (0)     [based on undef value] >
<2 x i32> %sext = < #x00000000 (0), #x00000000 (0) >
<2 x i32> %#1 = < #x00000000 (0), #x00000000 (0)       [based on undef value] >
<2 x i32> %mul = < #x00000000 (0), #x00000000 (0) >

Target:
<2 x i16> %ashr = < #x0000 (0), #xff80 (65408, -128) >
<2 x i16> %narrow = < #x0000 (0), #xfc00 (64512, -1024) >
<2 x i32> %mul = < #x00000000 (0), poison >
Source value: < #x00000000 (0), #x00000000 (0) >
Target value: < #x00000000 (0), poison >

Summary:
  0 correct transformations
 2 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV19v4jgQ_zTmxQI54yQ4Dzy0UKSTVjqpt7rXlZPY4CrYyHZou5_-FCdAgJQF9nRXVeDEv_nrmZ8Z7pxaaSFmKHlGyWLEa782dpYbvXqr9dsoN-XnbO391iH6hGCJYLlSfl3nk8JsECyrarf_Gm-teROFR7DMK5MjWHJKZZlGLAUhC0ILWQooChYXwKFM5VRGRZJkjPb0qEbuu-XaSWM3DsHyD-383GxypUX3ZOvCK6Pbl0qvJsV2i4B-A0rT8TegcYrIApGn9vOpUjsB2IqtsR7RJ3waDQ_bk8b-xNgVgmXR2PmJYFn6H_M31deFUtL-B3fDq_GNfy26FFJpgRUFjGLihfPsx04UE4qAqSjFCJK_EWQYTZ87i0BJ42t4wM0-d2uLEV3gsDgKzTHroZz48AEVFh0qSHjTmO9BEdDoRuimrgKy-Q4xtIYa452iPdgKv0ds6qqLZbroFnSB6Mt_nBHNrTXvB_e1e-_H2oUQlpfx_mwyo7VY7U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