LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 52093 - [x86] parity op gets transformed to popcount
Summary: [x86] parity op gets transformed to popcount
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Craig Topper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-06 10:06 PDT by Sanjay Patel
Modified: 2021-10-06 14:41 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s): 58b68e70ebf6308f982426a2618782f473218eed


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sanjay Patel 2021-10-06 10:06:56 PDT
define i32 @xor4_popcount(i32 %x) {
  %m = and i32 %x, 15
  %p = tail call i32 @llvm.ctpop.i32(i32 %m)
  %r = and i32 %p, 1
  ret i32 %r
}

declare i32 @llvm.ctpop.i32(i32)

--------------------------------------------------------------------
% llc -o - pop.ll              
	xorl	%eax, %eax
	testb	$15, %dil
	setnp	%al

% llc -o - pop.ll -mattr=popcnt
	andl	$15, %edi
	popcntl	%edi, %eax
	andl	$1, %eax

--------------------------------------------------------------------

Debug spew shows that we convert to a parity node either way, but then convert back to ctpop for a target that supports that instruction.

Test and set likely has better latency/throughput than popcnt + 2 mask instructions on all recent x86 CPUs.
Comment 1 Sanjay Patel 2021-10-06 10:07:21 PDT
This example is derived from the post-commit discussion in:
https://reviews.llvm.org/D110170
Comment 2 Craig Topper 2021-10-06 10:12:21 PDT
Can I take this?
Comment 3 Sanjay Patel 2021-10-06 10:18:37 PDT
(In reply to Craig Topper from comment #2)
> Can I take this?

Sure!
Comment 4 Craig Topper 2021-10-06 10:42:55 PDT
Candidate patch https://reviews.llvm.org/D111249
Comment 5 Craig Topper 2021-10-06 14:41:27 PDT
Should be fixed after 58b68e70ebf6308f982426a2618782f473218eed