<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84749>84749</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DAG] Match some basic ISD::AVGFLOORU 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::AVGFLOORU (assuming the target supports it):
define i4 @fixedwidth(i4 %a0, i4 %a1) {
%and = and i4 %a0, %a1
%xor = xor i4 %a0, %a1
%srl = lshr i4 %xor, 1
%res = add i4 %and, %srl
ret i4 %res
}
define i4 @zext_add_extract(i4 %a0, i4 %a1) {
%x0 = zext i4 %a0 to i5
%x1 = zext i4 %a1 to i5
%sum = add i5 %x0, %x1
%srl = lshr i5 %sum, 1
%res = trunc i5 %srl to i4
ret i4 %res
}
These will need aarch64 vector tests as thats the only target that has legal ISD::AVGFLOORU instructions so far.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlE1vtDYQxz-NuYyyAgPLcuCwCdq0aqtUSdtrZPAAbr145RmSTT_9I3t3k0hJHuXCIM9vXvljRWTGGbER5bUo20QtPDnf3P_2YPZuTjqnX5o_F2tRg1sY3AC_qP4_9EJWBC1aM04s5A10jqfg5QkJQXmEJ2WNhoNiRj8T8KQYejVDhzA4q1EDO_j1oRX5VuTb7T-3u9_v7u7_BiE3imjZm3kM2YCVH5GBlsPBeSYwLGQdgtJWpOenxsHMCKYAUaSDOaJ-NponITfhSJYqDT2e3zMhawBRXZ9iIR7OGkTeQrDvQ078G3d0PnLB_owjbyNnabqAR-cD-Z7ySKeq-rXqrM_pyNsL6ZHPbo90Hrtqv5z_fzzyo9L6EY_sVc_f38Ixje2EBK_Tha9kyvdQ9gHKPkC07N8mK0-5z4Mdv95TeQ79ak_sl7m_YN7GqsX3t_RX1OazsRZmRA1K-X5aF_CEPTsPjMQE6iRVitpzs325CDAKeFIEFkdlP1OumYn90rNxMwE5GJRfJbrJdZ3XKsEmq7I0Kzd1sUmmZp0XXZqmUkpdr7teyVyVRVqUfbYesq6qEtPIVBZpnmWZTDdFtcpUNei6rrt-LQuspShS3CtjV9Y-7VfOj4khWrDZFFVRJ1Z1aCn-1lKOzmkYjCeGyAgphbwRUoZQkW8f0GLsu93eBl_ZJr4JvqtuGUkUqTXE9FaIDdt4ZQS-bOEPxf0E5PYInSLTf7ady02QLN42E_OBAiF3Qu5Gw9PSrXq3F3IXWzqZq4N3_2JQ8C62TULu4nQ_AgAA__-tOl93">