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

    <tr>
        <th>Summary</th>
        <td>
            Requesting cost of invalid extending instruction
        </td>
    </tr>

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

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

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

<pre>
    At line
https://github.com/llvm/llvm-project/blob/fcb6a9c07cf7a2bc63d364e3b7f60aaadadd57cc/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L7745

the SLP vectorizer will request the cost of an invalid instruction performing an extension from a larger type to a smaller one whenever the slp decides that the reduction operation can be performed in lesser bits than the original type here:

https://github.com/llvm/llvm-project/blob/fcb6a9c07cf7a2bc63d364e3b7f60aaadadd57cc/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L7294

 Reproducer:
rep.ll
```
define i32 @c() {
entry:
  %rem.1 = srem i32 undef, 2
  %idxprom.1 = sext i32 %rem.1 to i64
  %arrayidx.1 = getelementptr inbounds i16, ptr @c, i64 %idxprom.1
  %rem.6 = srem i32 undef, 2
  %idxprom.6 = sext i32 %rem.6 to i64
  %arrayidx.6 = getelementptr inbounds i16, ptr @c, i64 %idxprom.6
 unreachable
}
```
opt --slp-vectorizer < rep.ll
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVE2PpDYQ_TXmUpqWMWCaA4fZGfVpDqvdKHd_FI0jY5OymZnOr4-A7k4nWkVa5RIJAXZVvfescj2VkjsHxJ41X1jzWqglj5F6G5KaZuVioaO99M8ZvAvI-Cvjz2POc2LVMxMnJk5nl8dFH0ycmDh5_377PM0Uf0OTmThpHzUTp8FoqTrDWzO0SmgjK1vJGivdDpIrpayytmmNecBxa90vpEIaIk2JidOvaHIk9wcycfr-9vW-pIOZZyaqt7atm13n_s4jwve3r_B-z4QP5z0Q_r5gyrDGTUwZ4gAqgAvvyjsLLqRMi8kuBpiRVnoXzmsGfmYMad0fKE6gwCs6I0G-zAg5goI0Ke-RIAaEjxEDvq_hESH5GSwaZzFBHtVOTmivPHFGUtufUQE03ohxlQMeU0IC7fJWHLbiSO7sgvI7-4iEa2Mejv8_b5bo6ke18A1ninYxSPdzEM4H769Zkl-fbWlxcAHBVQJYzQ0TRyY6YO2XPYwh0-WOA8BEQzgdSmDVKyTCaatcgsWBiRcQD3nOfs4U77n4mXeWG0KO4GT9UKCI1MXZz2vFGTN6nDDkORO4oOMSbAJXypVp3dsFv6wwfyP8h1j5E2LlD8XKfxEr_5tYecVcAqEyo9L-ahGsff1hw-Kc4ekp-fnpYRxZ9QJ7kwvbV7arOlVgX8qOt92xrMpi7LkehgZFw7Ut-VHqWg-yabuuqVA2ZmgK1wsuKt5WZcn5sSkPFhuJR95KO9S1OB5ZzXFSzh_W23qIdC5cSgv2shaNKLzS6NPmgUIE_IAtyIRYLZH6bUT0ck6s5t6lnP5CyS577L_tZrI6xM1Lbkay2YVdIw-WUizk-58ezU3UOleb6D8DAAD__6jxzl8">