Refactor number_of_iterations_popcount
authorAndrew Carlotti <andrew.carlotti@arm.com>
Tue, 4 Oct 2022 17:21:57 +0000 (18:21 +0100)
committerAndrew Carlotti <andrew.carlotti@arm.com>
Mon, 21 Nov 2022 16:00:51 +0000 (16:00 +0000)
commiteea52e38dd81b6632546b7cf933479986c972c69
treefa24b0afe74b834c489ea624c494c64b5c663125
parentfe985a236327c9d95a1b667abe7eb31afc9eb61c
Refactor number_of_iterations_popcount

This includes various changes to improve clarity, and to enable the code
to be more similar to the clz and ctz idiom recognition added in
subsequent patches.

We create new number_of_iterations_bitcount function, which will be used
to call the other bit-counting recognition functions added in subsequent
patches, as well as a generic comment describing the loop structures
that are common to each idiom. Some of the variables in
number_of_iterations_popcount are given more descriptive names, and the
popcount expression builder is extracted into a separate function.

As part of the refactoring, we also fix a bug where the max loop count
for modes shorter than an integer would be incorrectly computed as if
the input mode were actually an integer.

We also ensure that niter->max takes into account the final value for
niter->niter (after any folding and simplifying), since if the latter is a
constant, then record_estimate mandates that the two values are equivalent.

gcc/ChangeLog:

* tree-ssa-loop-niter.cc
(number_of_iterations_exit_assumptions): Modify to call...
(number_of_iterations_bitcount): ...this new function.
(number_of_iterations_popcount): Now called by the above.
Refactor, and extract popcount expression builder to...
(build_popcount_expr): this new function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/popcount-max.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/popcount-max.c [new file with mode: 0644]
gcc/tree-ssa-loop-niter.cc