public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/60973] New: Invalid propagation of a tail call in copyrename2 pass
@ 2014-04-26  8:27 ubizjak at gmail dot com
  2014-04-28  9:49 ` [Bug ipa/60973] Invalid propagation of a tail call in devirt pass rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2014-04-26  8:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60973

            Bug ID: 60973
           Summary: Invalid propagation of a tail call in copyrename2 pass
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com

This problem can be illustrated with a target, that doesn't define
TARGET_ASM_CAN_OUTPUT_MI_THUNK, such as h8300-elf.

Compiling g++.dg/ipa/imm-devirt-2.C using -O2 with a crosscompiler to
h8300-elf, we get in _.037t.inline_param2:

virtual int C::_ZThn10_N1C3fooEi(int) (struct C * const this, int i)
{
  int retval___0;

  <bb 2>:
  this_2 = this_1(D) + 65526;
  retval___0_5 = C::foo (this_2, i_4(D)); [tail call]
  return retval___0_5;

}

and

int main(int, char**) (int argc, char * * argv)
{
  struct C c;
  int _3;
  int _6;

  <bb 2>:
  C::C (&c);
  _3 = get_input ();
  _6 = C::_ZThn10_N1C3fooEi (&c.D.1912.D.1895, _3);
  if (_6 != 4)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  abort ();

  <bb 4>:
  c ={v} {CLOBBER};
  return 0;

}

However, copyrename2 pass propagates tail call annotation to the call site,
resulting in _.054t.copyrename2:

int main(int, char**) (int argc, char * * argv)
{
  int retval___0;
  int D.2161;
  struct C * const this;
  struct C c;
  int _3;
  int _6;

  <bb 2>:
  C::C (&c);
  _3 = get_input ();
  this_7 = &c.D.1912.D.1895 + 65526;
  retval___0_8 = C::foo (this_7, _3); [tail call]          <<< here!
  _9 = retval___0_8;
  _6 = _9;
  if (_6 != 4)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  abort ();

  <bb 4>:
  c ={v} {CLOBBER};
  return 0;

}

On a target that support sibcalls, RTL expansion ends after tail call, so
_.170r.expand ends with:

...

(call_insn/u/j 15 14 16 2 (set (reg:SI 3 r3)
        (call (mem:SI (symbol_ref:SI ("_ZN1C3fooEi") [flags 0x3] 
<function_decl 0x7fe46eeab200 foo>) [0 foo S4 A32])
            (const_int 0 [0]))) -1
     (expr_list:REG_EH_REGION (const_int 0 [0])
        (nil))
    (expr_list:SI (use (reg:SI 4 r4))
        (expr_list:SI (use (reg:SI 3 r3))
            (nil))))
;;  succ:       EXIT [100.0%]  (ABNORMAL,SIBCALL)

(barrier 16 15 0)


The tail call is valid only in _ZThn16_N1C3fooEi (a.k.a non-virtual thunk to
C::foo(int)) and should not be propagated as a tail call to its call site.


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

end of thread, other threads:[~2014-05-13 11:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-26  8:27 [Bug tree-optimization/60973] New: Invalid propagation of a tail call in copyrename2 pass ubizjak at gmail dot com
2014-04-28  9:49 ` [Bug ipa/60973] Invalid propagation of a tail call in devirt pass rguenth at gcc dot gnu.org
2014-05-06 11:28 ` hubicka at gcc dot gnu.org
2014-05-07 18:10 ` ubizjak at gmail dot com
2014-05-09 10:56 ` rguenth at gcc dot gnu.org
2014-05-09 14:27 ` hubicka at ucw dot cz
2014-05-13  7:57 ` rguenth at gcc dot gnu.org
2014-05-13 11:05 ` rguenth at gcc dot gnu.org
2014-05-13 11:06 ` rguenth at gcc dot gnu.org
2014-05-13 11:06 ` 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).