<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89338>89338</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
instcombine is wrong about a vector fshr->shl transformation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
Instcombine seems to be mis-optimizing this function:
```llvm
define i32 @f(<4 x i8> %0) {
%2 = call <4 x i8> @llvm.fshr.v4i8(<4 x i8> %0, <4 x i8> zeroinitializer, <4 x i8> <i8 -12, i8 -80, i8 35, i8 1>)
%3 = bitcast <4 x i8> %2 to i32
ret i32 %3
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i8> @llvm.fshr.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
the result is:
```llvm
define i32 @f(<4 x i8> %0) {
%2 = shl <4 x i8> %0, <i8 4, i8 0, i8 5, i8 7>
%3 = bitcast <4 x i8> %2 to i32
ret i32 %3
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i8> @llvm.fshr.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i8> @llvm.fshl.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
Alive says:
```
ERROR: Value mismatch
Example:
<4 x i8> %#0 = < #x00 (0), #x01 (1), #x00 (0), #x00 (0) >
Source:
<4 x i8> %#2 = < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >
i32 %#3 = #x00000000 (0)
Target:
<4 x i8> %#2 = < #x00 (0), #x01 (1), #x00 (0), #x00 (0) >
i32 %#3 = #x00000100 (256)
Source value: #x00000000 (0)
Target value: #x00000100 (256)
```
https://alive2.llvm.org/ce/z/s4UpPe
cc @hatsunespica
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVltv8zYM_TXyC5HAluzGfvBD2iTAnjZ0l3dZpmNushRIcnr59YPsNEnbfNu-XYBhWFE4EklRh8eHsqT3tDeINSvuWbFJ5Bh662qHe-xd0tj2pf7G-KDs0JBB8IiDh2ChQRjIL-wh0ECvZPYQevLQjUYFsoaJNUs3LF2zu3T-1_o4zKYWu5iKBAeWpx3jJRMPOTwDlUxsgfEiZbwCtrqf4yGaODCxASW1hvfR-ZR52fneLY85lbfTPbxf9YrOkqFAUtMruk9-Jh6ohEXGoyeOyvQ0EsVpkDGxZby6gigmiA0FJX2AjyB4ZI0Ef1vgMMwU8EKcqFptToP5Ke5hd6IT1iE4z8QajI0cNFL9AsZ2DhGM9S9GgbGjeSLTgj-gGrUMstEIT6S1wzA6AwMO1r0wXhpr8Iy8RaWlw68j9SNfn-cVMC7S63JkCI6aMaCfXBNXbHX_NxYEFwLfRDdPQ4_g0I86APl_SJm-_yjMi-6ohPykmjcZvaloFdn6X0J_TEL_jnL0f6Aj5uda0xHBy5cbTTFPt4-P3z5Gkn-SepxO_EEG1V8n2T7L4aDxkuGDaC-liYdY53OaAuPxPK0mkqIli5bs2vI55myBc8vMz-_t6NRv7s9_b_-vslz2P_Ue42Lu2zlu_juvv0L6g3R7DH8J6Z9k6otIszmaF3dnrDOfcIxvPL76L1c113Mj8kbWmwLsQzhM2uM7xncyypEvpz6zbs_4TiHju1fGdz7_8fAdXi9VKvZkL4MfDfoDKXntTdpatJWoZIJ1tspEXmVVmSV9naMoSmzKtitapbC9azFdtaJQxV3ZrLoqoZqnPE_zrEqzosqzpUzTXKyqIu140aYFsjzFQZI-40zI-xHrshKiTLRsUPvpMsX5QF7Z4UBaTlciHm8TjPPpeyPWdLlWRVexSVwdXYtm3Pt43pAP_rJLoKCxvloE5OHJWbMH2dgxgIQjqmAdxCN3wcQ2fpKCk8Z31g0ThGR0un5P-p5CPzZLZQfGdxOy-WdxcPZnVIHx3VSfZ3w3lfhrAAAA__-b-c7k">