public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/114185] New: Missed tail-call optimization due to an argument whose address is taken
@ 2024-03-01  6:25 dizhao at os dot amperecomputing.com
  2024-03-01  6:28 ` [Bug middle-end/114185] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dizhao at os dot amperecomputing.com @ 2024-03-01  6:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114185
           Summary: Missed tail-call optimization due to an argument whose
                    address is taken
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dizhao at os dot amperecomputing.com
  Target Milestone: ---

GCC (with "-Ofast") doesn't perform tail call optimization on a function like:

    long test_func (long n, unsigned long u64arg,
                    unsigned int u32arg, unsigned long *p)
    {
      if (n > 0)
        return test_func (n - 1, u64arg + (unsigned long) u32arg, u32arg, p);
      else
        return &u64arg - p;
    }

llvm can optimize the tail call.

GCC gave up tail call optimization, because the following check in
find_tail_calls() failed on argument "u64arg":

              /* The parameter should be a real operand, so that phi node
                 created for it at the start of the function has the meaning
                 of copying the value.  This test implies is_gimple_reg_type
                 from the previous condition, however this one could be
                 relaxed by being more careful with copying the new value
                 of the parameter (emitting appropriate GIMPLE_ASSIGN and
                 updating the virtual operands).  */
              if (!is_gimple_reg (param))
                break;

The check was to fix this ICE:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93487 . But in this case,
"&u64arg" won't be used in PHI argument, so it seems ok for tail call
optimization. (BTW, I tried current GCC trunk on the example code in PR 93487,
but haven't encounter the ICE with that check removed, because the PHI
arguments are "&y" and "&x" now.)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-01  7:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01  6:25 [Bug middle-end/114185] New: Missed tail-call optimization due to an argument whose address is taken dizhao at os dot amperecomputing.com
2024-03-01  6:28 ` [Bug middle-end/114185] " pinskia at gcc dot gnu.org
2024-03-01  6:31 ` pinskia at gcc dot gnu.org
2024-03-01  7:08 ` dizhao at os dot amperecomputing.com
2024-03-01  7:15 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).