[Bug tree-optimization/96930] Failure to optimize out arithmetic with bigger size when it can't matter with division transformed into right shift

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 5 15:34:27 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96930

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5ca2400270e985f9b33d93007f4d831299b9bda7

commit r11-6471-g5ca2400270e985f9b33d93007f4d831299b9bda7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 5 16:33:29 2021 +0100

    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.


More information about the Gcc-bugs mailing list