<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132922>132922</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Scalable splats don't have trunc constant folded
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lukel97
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/WGd66165o
```llvm
define <vscale x 1 x i8> @f() {
%1 = trunc <vscale x 1 x i64> splat (i64 1) to <vscale x 1 x i8>
ret <vscale x 1 x i8> %1
}
define <2 x i8> @g() {
%1 = trunc <2 x i64> splat (i64 1) to <2 x i8>
ret <2 x i8> %1
}
```
With `opt -p instcombine`, only the fixed-length vector splat has the truncate constant folded
```
define <vscale x 1 x i8> @f() {
ret <vscale x 1 x i8> trunc (<vscale x 1 x i64> splat (i64 1) to <vscale x 1 x i8>)
}
define <2 x i8> @g() {
ret <2 x i8> splat (i8 1)
}
```
The same thing also happens for ConstantExprs, but the fixed-length splat seems to be already folded before it even reaches InstCombine. I think it might be happening in the parser.
```llvm
define <vscale x 1 x i8> @h(<vscale x 1 x i8> %x) {
%1 = and <vscale x 1 x i8> %x, trunc (<vscale x 1 x i64> splat (i64 1) to <vscale x 1 x i8>)
ret <vscale x 1 x i8> %1
}
define <2 x i8> @i(<2 x i8> %x) {
%1 = and <2 x i8> %x, trunc (<2 x i64> splat (i64 1) to <2 x i8>)
ret <2 x i8> %1
}
```
After `opt` (no passes)
```llvm
define <vscale x 1 x i8> @h(<vscale x 1 x i8> %x) {
%1 = and <vscale x 1 x i8> %x, trunc (<vscale x 1 x i64> splat (i64 1) to <vscale x 1 x i8>)
ret <vscale x 1 x i8> %1
}
define <2 x i8> @i(<2 x i8> %x) {
%1 = and <2 x i8> %x, splat (i8 1)
ret <2 x i8> %1
}
```
I noticed this when trying to match some patterns for #132245
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzslk2P4zYMhn-NfCEmkOmPxAcfsjObYs4tsGfZpmN1ZcmQmDTTX1_I9mK-EnSnnd4KGMghlPiQr15RKgR9tES1KL6I4iFRJx6cr83pO5lqmzSue6oH5imIbC_wIPBwdF3jDG-cPwo8_Cnw8O2XrizTsnBC7uNXyuUz5jwKue-o15ZAZPfn0CpDcIEULqB3IvsKIpe9wJ3ACsT2i5B7AIFFCiJ7APYn275fV-ZxYZiMYhC402UOaVzP7nqOeVNPfIsAizRSbx8W_GdcfEl5fE35HhL_ng2vIeENkh9dXKi-aR5AlNJNDHcTaBu4dWOjLcUQvAdnzRPwQNDrC3V3huyRBzhTy86vQIMKc8SMrJigdTawsgy9Mx11b-T7uHS3m7x2CXf_Xk2sPq7W-14_J9zN-W71_beBIKiRgAdtj6BMcDCoaSIboHce7tcWfr1MPkQdmhO_l2HJFojGEAtrCJTxpLqntfPQUO88gWagM1nwpNqBAjzawPeLzBt4nBm-x6BRHweO2ywokUzbOe2kfCC_-WdOHK4J9ONoXq56VNnutq8usSGfLf0neFkvNPjT5b2NfF3Vh5z_uoafM_--Z_Kr-0Up4_7WwaRCoLCe3f_F_g_FvnJZfFDBR7COdUtd9HCAPwaywP4pGpcdjIrbAYIbo3-Zya-Xi8AszRDzIunqrKuySiVUp9scK5lLLJKhbirZF13b9H3eSFn2212GTRdD8qatlEp0jRILmWGRopRpucnTTKquapo-R9nLTOSSRqXNJh6bONQTHcKJ6jTDCjExqiET5tcB4nyysv3L4YMYXw2-jn_dNadjELk0OnB43o81m_l98eI2E8UD_NoqoxpDS3sDdM4K3MYxdV5n1NsBlZy8efsa0Tycmk3rRoGHmW_5uZu8-51aFniY6wkCD2tJ5xr_CgAA__86p4hn">