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

    <tr>
        <th>Summary</th>
        <td>
            Wrong swap between `sdiv` and `extractelement` by InstCombine
        </td>
    </tr>

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

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

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

<pre>
    https://alive2.llvm.org/ce/z/mGNeLx


```
----------------------------------------
define i8 @fun0(<4 x i8> %val0, i32 %val1) {
#0:
  %val2 = sdiv <4 x i8> { 42, 42, 42, 42 }, %val0
  %val3 = extractelement <4 x i8> %val2, i32 %val1
 ret i8 %val3
}
=>
define i8 @fun0(<4 x i8> %val0, i32 %val1) {
#0:
  %#1 = extractelement <4 x i8> %val0, i32 %val1
  %val3 = sdiv i8 42, %#1
  ret i8 %val3
}
Transformation doesn't verify!

ERROR: Source is more defined than target

Example:
<4 x i8> %val0 = < #x01 (1), #x08 (8), #x02 (2), #x04 (4) >
i32 %val1 = #x20000000 (536870912)

Source:
<4 x i8> %val2 = < #x2a (42), #x05 (5), #x15 (21), #x0a (10) >
i8 %val3 = poison

Target:
i8 %#1 = poison
i8 %val3 = UB triggered!


Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```


`sdiv` and `extractelement` cannot be swapped for vector operands as it can trigger UB, diving an integer by `poison`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VdGOqzYQ_RrnZbSRGUOABx42N5uqUtVK23vVZwMT4iuwI9uwSb--MpAtpNvbfSmKCB7GZ845HmzpnGo0UcGSPUsOG9n7s7FFafT3XtOmNPWtOHt_cUw8MzwyPMpWDYTbth26rbENw2NFDI9_Mjx2P_1Kv1wZPzD-vLrv-Pwbh0-fvKbsmk5KE6gMWMxPveYMMya-xHAFlTHxAgyTQbac4RdQAudhxDAHlu5nAih4EDAOYE5BYOIArlYDrPHSPcQY4NZ3YOkhPN3rrcDECEZXb2XlqaWOtIcPaOIjzQnFkh8VTlgz6fQwP4gDEy__pxsMRfRJAf9A_sCG0VOVzc7N-PfEH0r9aqV2J2M76ZXRUBtymmHqYSCrTjeG0bKvXl5ff3tl4hl-N72tCJSDzliCyaQa_Flq8NI25FfTrrK7tPRuwUcqRx1MBPbiyiNgmAUTJz3iyoOALFtGgiMZLiNxiMSj9fflWxg3VUBxRT5dITsRuyzleTTiLChPAn_EGFeMUY61V3SSscAiEo0RXOka50V8TTpbre7FKGf0kt3XyeI7uyn_vaeW-Q9Q3_bgrWoaslQ_rO2su-86aW-LbuVQGWup8uBXveLuCREo_R8pHE5StVQ_efN0sWagf098Hnc7IGuNdR_uZg8bXeh9tuMgdQ1sx9cfVHhRSa2Nh5LAvcnLhWo4GQsDVd5YMBeyUtcOpAPlQ-7dIPi2D4tUq0HpBqQGpT2FeHkLdWaTd3y7qQtR5yKXGyqiNMqTNE8w2ZyLKq7iMqKYsqxMRFJTle4or1GcsrrMBW5UgRxjvsMswiSLky1mO5RVSbucZ8iRWMypk6p93_w3yrmeijzlidi0sqTWjQcJoqY3GF8yxHCu2CLMeSr7xrGYt8p59zeKV76l4g9rdDOaAiX5NyINn_GzvMHP2vkvpiuVpk1v24cDq1H-3JfbynQMj6Hm_BeW_jtVnuFxZOoYHiclQ4F_BQAA___C9vFu">