Set nonzero bits for multiplication and divisions by a power of 2.
authorAldy Hernandez <aldyh@redhat.com>
Fri, 4 Nov 2022 09:20:46 +0000 (10:20 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 4 Nov 2022 14:18:18 +0000 (15:18 +0100)
commit679be32e66428f0ba81d1c1b55f7bd47f01cb295
tree1f0f72dae83381e8c67ce106a470fef92043f39b
parent0bdf10bdf1b2c9f31e7e764dec4d56ea6044f943
Set nonzero bits for multiplication and divisions by a power of 2.

We're missing a lot of TLC in keeping track of nonzero bits across
range-ops.  It isn't an oversight, but just limited amount of hours to
implement stuff.

This patch keeps better track of the nonzero mask (really
maybe_nonzero bits as discussed) across multiplication and division
when the RHS is a power of 2.

It fixes PR107342 and also touches on PR55157.  In the latter, the
nonzero mask is being set quite late (CCP2) but could be set by evrp
time if we enhanced range-ops.  I have added tests from both PRs.

Tested

PR tree-optimization/107342

gcc/ChangeLog:

* range-op.cc (operator_mult::fold_range): New.
(operator_div::fold_range): New.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp122.c: New test.
* gcc.dg/tree-ssa/vrp123.c: New test.
gcc/range-op.cc
gcc/testsuite/gcc.dg/tree-ssa/vrp122.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/vrp123.c [new file with mode: 0644]