Closed
Description
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.