[Bug tree-optimization/60973] New: Invalid propagation of a tail call in copyrename2 pass

ubizjak at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Apr 26 08:27:00 GMT 2014


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.



More information about the Gcc-bugs mailing list