<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84753>84753</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DAG] Match some basic ISD::AVGCEILU patterns
</td>
</tr>
<tr>
<th>Labels</th>
<td>
good first issue,
llvm:SelectionDAG
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
Pulled out of Hacker's Delight, both of these are valid patterns that can be folded to ISD::AVGCEILU (assuming the target supports it):
```ll
define i4 @fixedwidth(i4 %a0, i4 %a1) {
%or = or i4 %a0, %a1
%xor = xor i4 %a0, %a1
%srl = lshr i4 %xor, 1
%res = sub i4 %or, %srl
ret i4 %res
}
define i4 @zext_add_inc_extract(i4 %a0, i4 %a1) {
%x0 = zext i4 %a0 to i5
%x1 = zext i4 %a1 to i5
%sum = add i5 %x0, %x1
%inc = add i5 %sum, 1
%srl = lshr i5 %inc, 1
%res = trunc i5 %srl to i4
ret i4 %res
}
```
Both aarch64 and x86 have some ISD::AVGCEILU vector support, so we can test this with either - x86 already has a rather messy detectAVGPattern function that I hope we can eventually get rid of and just have a regular DAG combine, so try to keep away from that for now :)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlFFvozgQxz-NeRm1AgMhPPCQlkuvujtpddXta2XwEHvX4MgeEnKf_mST7Fa3XW2lKIDnN-P_jGcsvNeHCbFh5QMr20TMpKxr_v7jRY92SjorL82n2RiUYGcCO8Dvov-KjvHKQ4tGHxQx_gidJRWspNAjCIdwEkZLOAoidJMHUoKgFxN0CIM1EiWQheeXluU7lu92n58ef3v-8x9gfCu8n0c9HUIwIOEOSODn49E68qCJ8Tr4pC1Lb_-bdP0Zsy5IHPSEoAtgRTroBeVZS1KMb8MSL0UaNF_fM8ZrAFY9rL4QFq0DlrdgHbx1WOnv1HLFll9w3pnIGa9u4GJdIN9SDn2k_NxdoZVZA9xAh3S1OvTX9Kv2nbT_xYVehZSveupfcSEnevp4AZY0aglBvqUWDkyXb6HsByj7AfLzGCkhJehyjX1Na3mbvp76_3F-HmON4KelLK-OPysluXnqb9GcidqKj1TyW0etnw-hu4VwvdoUICYJy3YDSpwQvB3xnS4-YU_W3bo2yPMWzhgHgNATkNIezpoUoCaFDu5iTGEcCnkBJTwIcCKaRvT-AhIJe9p9fvq0jhQM89STttM6Ws-g7BFve-AJJ5qFMRcI0-O0DMMZlH-ZPa3SBTg8zEY4aHdP0Nux0xNepZK7hGJ9RTyCOIsLDM6O60aDdTDZM4SMeZ3IJpd1XosEm6zK0myTFnWZqAarstsUKQ7bKq17iSXn3YCbSpbb7aarN4lueMqLNM-yjOdFUd8XVYW56LZDUddZX2esSHEU2twbcxrvrTsk2vsZm21RlXliRIfGx2uL84O1EgbtPEFkGOeMPzLOgyvLdy9oMNaq3T0FW9kmrgm2u24-eFakRnvy3zciTSZeiYEvW_hLUK_Ws-6E1_07J3676JLZmUYRHX0s0J7x_UGTmrv73o6M76Oi9XF3dPYLhqncR9We8X1M7r8AAAD___wopms">