tree-optimization/114760 - check variants of >> and << in loop-niter
commit1b0919cd147a2b6ccdee2b1217bf0200bdcc87aa
authordzhao.ampere <di.zhao@amperecomputing.com>
Fri, 10 May 2024 03:55:18 +0000 (10 11:55 +0800)
committerDi Zhao <dizhao@os.amperecomputing.com>
Sat, 11 May 2024 09:59:12 +0000 (11 17:59 +0800)
treeaa44eb31cfc9ffd4a843079a00586d36db086cbb
parent18c93c65a9fbaaf3762198e78fb3c24b9b6fd9fc
tree-optimization/114760 - check variants of >> and << in loop-niter

When recognizing bit counting idiom, include pattern "x * 2"
for "x << 1", and "x / 2" for "x >> 1" (given x is unsigned).

gcc/ChangeLog:
PR tree-optimization/114760
* tree-ssa-loop-niter.cc (is_lshift_by_1): New function
to check if STMT is equivalent to x << 1.
(is_rshift_by_1): New function to check if STMT is
equivalent to x >> 1.
(number_of_iterations_cltz): Enhance the identification
of logical shift by one.
(number_of_iterations_cltz_complement): Enhance the
identification of logical shift by one.

gcc/testsuite/ChangeLog:
PR tree-optimization/114760
* gcc.dg/tree-ssa/pr114760-1.c: New test.
* gcc.dg/tree-ssa/pr114760-2.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/pr114760-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr114760-2.c [new file with mode: 0644]
gcc/tree-ssa-loop-niter.cc