<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56531>56531</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] Failure to use neon ops for parity calculations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
https://simd.godbolt.org/z/M4qjv6Phc
For ctpop ops, aarch64 uses the neon instructions if they're available to perform fast population count. But if this has been changed into a ISD::PARITY node, then it remains on the scalar unit.
```
define i64 @pop(i64 %x) {
%1 = tail call i64 @llvm.ctpop.i64(i64 %x)
ret i64 %1
}
define i64 @parity(i64 %x) {
%1 = tail call i64 @llvm.ctpop.i64(i64 %x)
%2 = and i64 %1, 1
ret i64 %2
}
declare i64 @llvm.ctpop.i64(i64 %x)
```
```
pop: // @pop
fmov d0, x0
cnt v0.8b, v0.8b
uaddlv h0, v0.8b
fmov w0, s0
ret
.Lfunc_end0:
parity: // @parity
eor x8, x0, x0, lsr #32
eor x8, x8, x8, lsr #16
eor x8, x8, x8, lsr #8
eor x8, x8, x8, lsr #4
eor x8, x8, x8, lsr #2
eor w8, w8, w8, lsr #1
and x0, x8, #0x1
ret
.Lfunc_end1:
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VFtvmzAU_jXwcjRkTLjkgQe6KFK1TaravexpMuAEd2BntknT_fodG2jTtJryMok4nPt3DsdfrdrnsrP2YIKkCugWHyOGNtqrtla9jZTeo-oP_r6tfj8es7uuCcgmINV0bpWGxh7UARRmoJ-BMd102QpGww3YjoPkSoKQxuqxsUJJA2LnDM8BzTUHdmSiZ3XPwSo4cL1TeoAdMxYw6dgzFwKNGqWN4Ga0U7Aw0DEDNedo65jc8xZLYAIGtw8b10hS3VX3t99_gFQtd7iwIsKwoPnAEA1gVofONKxnGkYpbHTeV5CR-fFiy3dCchDYWLAiiCyghRdoegroGoL8ZnIEp4ohSDZgsTHA9P0S1vfHIfLDilDzNsMSrbmFWR3PSPLNhxiYFvb5f8FAkfpoJttXPDjG-AOg9B3QBmfKr693MewL0U07qWDazWX8M4rdoI7QEofsRBZlIy0cSVTUTj29zJaRtW1_hI68s_hET15vyFmP02v0dTfK5ieXWCqZN2T-AG-RTbo5nOPdOBUztpezNxojkoR-4HZ2zm5xdpVbcZXX6iqvN8CevOX8XIAtXm5D5v68HW3kFP9jhPHLCC8-dNiWSbtO1iy0wva8DNKbqvJsEqQb2OIej9rTBHLLRCvIOYCEAdPc3ZY3M2WYcNT9Ba_the3GOmrUgILbyvnv00GrR95YFIUxI0ce26ZZmsRhV5I1KXhdsCxO45zGBaM0izNWJG22Xq0ZDZG7eG8c1oDSmjW_sEOsuACnFLGHoqSEUpLHqzhPSJJEdU5qxgpStDRPaRHj7jhe6iN_WZBzQ116aPW4N-4OCWPNq5EZI_aS-xG5_Gy0ndLl_ZcHMSgZ-i5K38JfiyOnUA">