Skip to content
Snippets Groups Projects
Commit 75a4143d authored by Andrew Pinski's avatar Andrew Pinski
Browse files

middle-end: also optimized `popcount(a) <= 1` [PR90693]


This expands on optimizing `popcount(a) == 1` to also handle
`popcount(a) <= 1`. `<= 1` can be expanded as `(a & -a) == 0`
like what is done for `== 1` if we know that a was nonzero.
We have to do the optimization in 2 places due to if we have
an optab entry for popcount or not.

Built and tested for aarch64-linux-gnu.

	PR middle-end/90693

gcc/ChangeLog:

	* internal-fn.cc (expand_POPCOUNT): Handle the second argument
	being `-1` for `<= 1`.
	* tree-ssa-math-opts.cc (match_single_bit_test): Handle LE/GT
	cases.
	(math_opts_dom_walker::after_dom_children): Call match_single_bit_test
	for LE_EXPR/GT_EXPR also.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/popcnt-le-1.c: New test.
	* gcc.target/aarch64/popcnt-le-2.c: New test.
	* gcc.target/aarch64/popcnt-le-3.c: New test.

Signed-off-by: default avatarAndrew Pinski <quic_apinski@quicinc.com>
parent 8f3b402b
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment