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

--- Comment #23 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:e7c3a7ccd6209c1a906bdf59207f0fa4258b692b

commit r15-9246-ge7c3a7ccd6209c1a906bdf59207f0fa4258b692b
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Apr 7 11:57:36 2025 +0200

    tailc: Extend the IPA-VRP workaround [PR119614]

    The IPA-VRP workaround in the tailc/musttail passes was just comparing
    the singleton constant from a tail call candidate return with the ret_val.
    This unfortunately doesn't work in the following testcase, where we have
      <bb 5> [local count: 152205050]:
      baz (); [must tail call]
      goto <bb 4>; [100.00%]

      <bb 6> [local count: 762356696]:
      _8 = foo ();

      <bb 7> [local count: 1073741824]:
      # _3 = PHI <0B(4), _8(6)>
      return _3;
    and in the unreduced testcase even more PHIs before we reach the return
    stmt.

    Normally when the call has lhs, whenever we follow a (non-EH) successor
    edge, it calls propagate_through_phis and that walks the PHIs in the
    destination bb of the edge and when it sees a PHI whose argument matches
    that of the currently tracked value (ass_var), it updates ass_var to
    PHI result of that PHI.  I think it is theoretically dangerous that it
    picks the first one, perhaps there could be multiple PHIs, so perhaps safer
    would be walk backwards from the return value up to the call.

    Anyway, this PR is about the IPA-VRP workaround, there ass_var is NULL
    because the potential tail call has no lhs, but ret_var is not
TREE_CONSTANT
    but SSA_NAME with PHI as SSA_NAME_DEF_STMT.  The following patch handles
    it by pushing the edges we've walked through when ass_var is NULL into a
    vector and if ret_var is SSA_NAME set to PHI result, it attempts to walk
    back from the ret_var through arguments of PHIs corresponding to the
    edges we've walked back until we reach a constant and compare that constant
    against the singleton value as well.

    2025-04-07  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/119614
            * tree-tailcall.cc (find_tail_calls): Remember edges which have
been
            walked through if !ass_var.  Perform IPA-VRP workaround even when
            ret_var is not TREE_CONSTANT, in that case check in a loop if it is
            a PHI result and in that case look at the PHI argument from
            corresponding edge in the edge vector.

            * g++.dg/opt/pr119613.C: Change { c || c++11 } in obviously C++
only
            test to just c++11.
            * g++.dg/opt/pr119614.C: New test.

Reply via email to