match.pd: Improve (A / (1 << B)) -> (A >> B) optimization [PR96930]
The following patch improves the A / (1 << B) -> A >> B simplification,
as seen in the testcase, if there is unnecessary widening for the division,
we just optimize it into a shift on the widened type, but if the lshift
is widened too, there is no reason to do that, we can just shift it in the
original type and convert after. The tree_nonzero_bits & wi::mask check
already ensures it is fine even for signed values.
I've split the vr-values optimization into a separate patch as it causes
a small regression on two testcases, but this patch fixes what has been
reported in the PR alone.
2021-01-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/96930
* match.pd ((A / (1 << B)) -> (A >> B)): If A is extended
from narrower value which has the same type as 1 << B, perform
the right shift on the narrower value followed by extension.
* g++.dg/tree-ssa/pr96930.C: New test.