From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 633 invoked by alias); 26 Apr 2014 08:27:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 608 invoked by uid 48); 26 Apr 2014 08:26:56 -0000 From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/60973] New: Invalid propagation of a tail call in copyrename2 pass Date: Sat, 26 Apr 2014 08:27:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-04/txt/msg01975.txt.bz2 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; : 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; : C::C (&c); _3 = get_input (); _6 = C::_ZThn10_N1C3fooEi (&c.D.1912.D.1895, _3); if (_6 != 4) goto ; else goto ; : abort (); : 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; : 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 ; else goto ; : abort (); : 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] ) [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.