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

    <tr>
        <th>Summary</th>
        <td>
            [VectorCombine] UB triggered after optimization
        </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/c93e001ca695e905cb965b36d63f7a348d1dd809/llvm/lib/Transforms/Vectorize/VectorCombine.cpp#L1013-L1031

Alive2 report: https://alive2.llvm.org/ce/z/78CM4x

```llvm
----------------------------------------
define <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {
#0:
  %ins = insertelement <2 x i8> poison, i8 %x, i32 3
  %bo = sdiv <2 x i8> %ins, { 5, 2 }
  ret <2 x i8> %bo
}
=>
define <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {
#0:
  %bo.scalar = sdiv i8 %x, poison
  %bo = insertelement <2 x i8> poison, i8 %bo.scalar, i64 3
 ret <2 x i8> %bo
}
Transformation doesn't verify!

ERROR: Source is more defined than target

Example:
i8 %x = poison

Source:
<2 x i8> %ins = < poison, poison >
<2 x i8> %bo = < poison, poison >

Target:
i8 %bo.scalar = UB triggered!



----------------------------------------
define <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {
#0:
  %ins = insertelement <2 x i64> poison, i64 %x, i32 4294967295
  %bo = urem <2 x i64> %ins, { 5, 2 }
  ret <2 x i64> %bo
}
=>
define <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {
#0:
  %bo.scalar = urem i64 %x, poison
  %bo = insertelement <2 x i64> poison, i64 %bo.scalar, i64 4294967295
  ret <2 x i64> %bo
}
Transformation doesn't verify!

ERROR: Source is more defined than target

Example:
i64 %x = poison

Source:
<2 x i64> %ins = < poison, poison >
<2 x i64> %bo = < poison, poison >

Target:
i64 %bo.scalar = UB triggered!


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/eJzEVstu4zYU_Rp6Q8TgQ8-FFokdr6YokGm7NUjxymYgkQJJuUm-vpDkaCS7g7E7aGsYsizdx7mH9wBHeK8PBqBA8ROKtyvRhaN1hbTm8NqZ15W06r04htB6xB8R2yG2O-hw7OS6tA1iu7o-ff48tM6-QhkQ28naSsR2Zc6BEFqKJI8hJ3Ep8ySWPFEJr1LBo0xRpTKSz-roPu83J4yvrGs8Yrs_oAzW6Q-Y7je2kdrAumxbxPgXSih_-EIJp4hsEXkcr4-1PgHDDlrrAuKPeDmEGF6v-7Zr6w492L7BB2K7NNv8Er3Na6GEjN8B5fDo4cbPGK2g0gYw4huG37DOEH_GKCJe6dO-tMYHYcLetnRvbNh3RkG1r4WBNUMs0xlGLH5DLMcofToDYpz0owx_cP9eG48R32JtPLgANTRgwrJha7W3BrENnkpusOYM81kdaYcyPbILuEOPPgWlTzjubxhG6fYz10G4SpD2DPczDPEt4s__FSfSrn0pauG-jTSb_EzH1eh3MDg1GB4l0cTkTWRMWy6CtgYrC94glgZ8Aqerd8QW-_z88vLrS7_HX23nSsDa48Y6wCONCoejMDgId4CwSHsTTVvDRMyZgGHSOQPjdaw9Bf_NAgyJiG9mXIx3eDrY68FvSRopGfEvwS6P8fcnHJw-HMCBuqBofv0pfSbReRk7B82PlzGJfl6hY8vZgk1FR41GLI_yJGV5fL2xPcpL7Heodcq4R67_CkXLkx7GmvNwn2K_w-iVZq-ZvY2c_0e-Zzru0-98J-4Q8Gz2f6zgC9Jvk_DXrmmEe58tB8GldQ7KgMOCdv8ZwLA2PwghuBK6BvUQbG9VTvD9wLN5AOes8xceYKUKrnKeixUUNOWU0oymyepYgMqSiok8olLGSZJXlcgyKZI4VSQVSbLSBSMsopTkhJGcx2tJIkUjmUvGkyynDEUEGqHryZastPcdFJTGcRqvaiGh9oNTY8zAn3h4ixjrjZsrBg8mu4NHEam1D_5bmaBDPVi8hYFC8fIssKgCOGzboBv9MXCy6lx9v_0bcPXe7Qz8VLC_AgAA__-Fgu96">