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

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

https://gcc.gnu.org/g:0691f7517ef50538c182eb623cd5d1cb1680f6cf

commit r13-9586-g0691f7517ef50538c182eb623cd5d1cb1680f6cf
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Jan 31 11:02:41 2025 +0100

    niter: Make build_cltz_expr more robust [PR118689]

    Since my r15-7223 the niter analysis can recognize one loop during
bootstrap
    as being ctz like.
    The patch just turned
    @@ -2173,7 +2173,7 @@ PROC m2pim_NumberIO_BinToStr (CARDINAL x
       _T535_44 = &buf[i.40_2]{lb: 1 sz: 4};
       _T536_45 = x_21 & 1;
       *_T535_44 = _T536_45;
    -  _T537_47 = x_21 / 2;
    +  _T537_47 = x_21 >> 1;
       x_48 = _T537_47;
       # DEBUG x => x_48
       if (x_48 != 0)
    which is not a big deal for the number_of_iterations_cltz optimization, it
    recognizes both right shift by 1 and unsigned division by 2 (and similarly
    for clz left shift by 1 or multiplication by 2).
    But starting with forwprop1 that change also resulted in
    @@ -1875,9 +1875,9 @@ PROC m2pim_NumberIO_BinToStr (CARDINAL x
       i.40_2 = (INTEGER) _T530_34;
       _T536_45 = x_21 & 1;
       MEM <CARDINAL[1:64]> [(CARDINAL *)&buf][i.40_2]{lb: 1 sz: 4} = _T536_45;
    -  _T537_47 = x_21 / 2;
    +  _T537_47 = x_21 >> 1;
       # DEBUG x => _T537_47
    -  if (x_21 > 1)
    +  if (_T537_47 != 0)
         goto <bb 3>; [INV]
       else
         goto <bb 8>; [INV]
    and apparently it is only the latter form that number_of_iterations_cltz
    pattern matches, not the former (after all, that was the exact reason
    for r15-7223).
    The problem is that build_cltz_expr assumes if IFN_C[LT]Z can't be used it
    can use the __builtin_c[lt]z{,l,ll} builtins, and while most of the FEs do
    create them, modula 2 does not.

    The following patch just lets us punt if the FE doesn't build those
builtins.
    I've filed a PR against modula2 so that they add the builtins too.

    2025-01-31  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/118689
            PR modula2/115032
            * tree-ssa-loop-niter.cc (build_cltz_expr): Return NULL_TREE if fn
is
            NULL and use_ifn is false.

    (cherry picked from commit 85e1714b0606579a339c234510063e057fe662af)

Reply via email to