<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153570>153570</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[X86] Selection failure with llvm.x86.avx512fp16.mask.mul.sh.round
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86,
crash
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
https://llvm.godbolt.org/z/cad6zh3Ys
```llvm
; RUN: llc -mattr=+avx512fp16 < %s
define <8 x half> @test_mm_maskz_mul_round_sh(ptr %p) {
%r = tail call <8 x half> @llvm.x86.avx512fp16.mask.mul.sh.round(<8 x half> <half 0xH3C00, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000>, <8 x half> <half 0xH4000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000>, <8 x half> zeroinitializer, i8 0, i32 8)
store <8 x half> %r, ptr %p, align 16
%r1 = tail call <8 x half> @llvm.x86.avx512fp16.mask.mul.sh.round(<8 x half> <half 0xH3C00, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000>, <8 x half> <half 0xH4000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000, half 0xH0000>, <8 x half> zeroinitializer, i8 1, i32 8)
ret <8 x half> %r1
}
```
```
LLVM ERROR: Cannot select: t26: v8f16 = X86ISD::SELECTS t45, t22, t9
t45: v1i1 = BUILD_VECTOR Constant:i8<0>
t22: v8f16 = X86ISD::FMULS_RND t43, t42, TargetConstant:i32<0>
t43: v8f16,ch = X86ISD::VZEXT_LOAD<(load (s16) from constant-pool)> t0, t37
t37: i64 = X86ISD::Wrapper TargetConstantPool:i64<half 0xH3C00> 0
t42: v8f16,ch = X86ISD::VZEXT_LOAD<(load (s16) from constant-pool)> t0, t39
t39: i64 = X86ISD::Wrapper TargetConstantPool:i64<half 0xH4000> 0
t9: v8f16 = BUILD_VECTOR ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>, ConstantFP:f16<APFloat(0)>
```
The selection failure for the reduced test case is not new, but we've only started hitting this with LLVM 21, probably due to IR optimization changes.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVktv2zgQ_jX0ZRBBGup58EGRbWwAtwmcx2b3YlASbXFDiQJJ5eFfvyCTNmmcAj3stpcCAqghZr75yI8cDjNG7AfO5yQ5JclixibbKT0fxJ1oZrVqn-adtaMhtCS4IriS8r4P9qqtlbSB0nuCqwPBVcPa9NDRvwwJS5KGz5_zdTY9hc31Z0JLkLKBk55ZqwldEDxl949JhLsxSoHQCggmDqDlOzFwN5PDI3RM7ghdAolDy43d9v22Z-busO0nudVqGtqt6Qjmo9UOYCRYAMlOSViCszUQugDLhISGSfkBql_SY54Gr2wClyHoJxmYLvA5CObvI2nlfiF8_INWYUiwgi92GP4Emy7d1PdJxT-DxA-ROnCtxCCsYFIcuHYeIgcfLChCTrDwahmr9LHsmPiIV3krYFLsB4jSrxpHv0X-1aQ-Fjk6Ellz-5HEkSsU2eJt-XD_35rr9c0nWG425xtXTCo2DMqC4ZI31k1YTN1wn-98PVnAbZ6eXS5c7aLl5XK9rK4uwcaJ42QR_fBMyk26yEg8n6TT67P1YnuzrK7ON1CpwVg2uBTCnQ-_AWHpIb6bbvXpen253XxegI2pzxT7hFdM77l9C0nxDSaA9_8CS7BquiPsm7-Xt1fb9Xm5ILQimEvFWiCYGxdQwE6rHpqXDCejUtLtPV2C9VJamnn2NHNpRBof4f-p2Thy_Y7rhQOipUjj95eCLiH8Sh7_Z_LFM_niPyAfh2_J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