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

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

https://gcc.gnu.org/g:20e5aa9cc1519f871cce25dbfdc149d9d60da779

commit r15-7947-g20e5aa9cc1519f871cce25dbfdc149d9d60da779
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Mar 11 11:01:55 2025 +0100

    tree: Improve skip_simple_arithmetic [PR119183]

    The following testcase takes very long time to compile, because
    skip_simple_arithmetic decides to first call tree_invariant_p on
    the second argument (and indirectly recurse there).  I think before
    canonicalization of operands for commutative binary expressions
    (and for non-commutative ones always) it is pretty common that the
    first operand is a constant, something which tree_invariant_p handles
    immediately, so the following patch special cases that; I've added
    there a tree_invariant_p call too after the checks, while it is not
    really needed currently, tree_invariant_p has the same checks, I wanted
    to be prepared in case tree_invariant_p changes.  But if you think
    I should avoid it, I can drop it too.

    This is just a partial fix, I think one can certainly construct a testcase
    which will still have horrible compile time complexity (but I've tried and
    haven't managed to do so), so perhaps we should just limit the recursion
    depth through skip_simple_arithmetic/tree_invariant_p with some defaulted
    argument.

    2025-03-11  Jakub Jelinek  <ja...@redhat.com>

            PR c/119183
            * tree.cc (skip_simple_arithmetic): If first operand of binary
            expr is TREE_CONSTANT or TREE_READONLY with no side-effects, call
            tree_invariant_p on that operand first instead of on the second.

            * gcc.dg/pr119183.c: New test.

Reply via email to