<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135617>135617</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] Failure to use `CBB` and `CBH` with `FEAT_CMPBR`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kmeakin
</td>
</tr>
</table>
<pre>
`FEAT_CMPBR` from armv9.5a adds [CBB](https://armv8.arm.com/latest_builds/v9A/isa64/cbbcc_regs.xml), [CBH](https://armv8.arm.com/latest_builds/v9A/isa64/cbhcc_regs.xml) and [CB](https://armv8.arm.com/latest_builds/v9A/isa64/cbcc_regs.xml) instructions. LLVM is able to generate `CB` instructions for comparisons between 32-bit and 64-bit types, but it does not generate `CBB` or `CBH` for comparisons between 8-bit or 16-bit types; instead it zero/sign extends to 32-bits and uses `CB`:
https://godbolt.org/z/xW71dqv4h
```c
u8_w0_eq_w1:
and w8, w1, #0xff
and w9, w0, #0xff
cbne w9, w8, .LBB0_2
b taken
.LBB0_2:
b not_taken
/*
*
* u8_w0_eq_w1:
* and w8, w1, #0xff
* and w9, w0, #0xff
* cbne w9, w8, .LBB0_2
* b taken
* .LBB0_2:
* b not_taken
*/
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyslN9uqzgQxp_G3FhBxvwJXHAR0kWVtpVWq9WeS2TjSfAp4NQ2Ie3TH9lp0iTN0bkpsuQQfvpmvrFnmDFyOwKUKK1Q-hCwyXZKl38PwF7kGHAl3kqUkfqv1X_N-vmf6l-UEbzRasBMD_siTBlmQhiM0mpdOQVE887anUHxCtEa0dpxecj0ELZqQLTumQVjGz7JXhhE633hQGlYliBat5y3baNha8LD0CNaILo-ij9-h3h3LY7ZKI7q3yF-oy1HY_XUWqlGE-Knp_-fsTSY8R6wVXgLI2hmAaOMrCtX1Useb5TGrRp2TEvj3jnYGWDEMV1waX3eWeJ_2rcdGFclPlksLRYKDB6VvYngQyh9fHn0p_ibELmXVRpH2UWAuPIJAhMuyDtohWjt7g6Gg4VRGGfqmJ3x6U0GzNmcqylx67rCWyW46m2o9BbR-h3R-vBjGYnXfdI5PCPH1SKymvJmJg28NnN0FMMfj4s1564Ac-QvC43JYbO5Idwz-8s0k_tUy0e4oLxi-FRVpKEXFP_YLXuBEZHVibhK6QSNyjYn0C3n2XOfG_7qy_17nfd9d1-5-_7O3B8cnrlbj_7LtdEze9er90fryyM8ViAQZSyKuGABlNEySTJaFEkUdCUpIIdctMBj4BGjOWWQtinZbAogS74MZEkJTUkSJVFE0yQKi2QDUORxFLM8EqRACYGByT7s-_3gLlQgjZmgjOI0i5ZBzzj0xk85SjlrX2AUKF6tVrrtXPtSRNeI0kEaA2KhdlYO8p25XnTf0odAl054waetQQnppbHmM5SVtvcj9KSXPuCayX7Svtcnc9mEfuacu3CWtsO3EzaYdF_etIq03cRPk6jfn7bFTquf0Fo_iczkRkH94Xlf0l8BAAD__-DSstY">