Optimization lost for tail-call to a noreturn function

Bug #1646605 reported by Gary Fuehrer
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

Correctly this:
void __attribute__((noinline)) bar() { __asm ("0: b.n 0b"); }
void Reset_Handler() { <any-not-need-LR-code>; bar(); }
 gives:
<Reset_Handler>:
  <any-not-need-LR-code>
  b.w <bar>

But either:
void __attribute__((noinline)) bar() { G: goto G; }
 or this:
void __attribute__((noinline, noreturn)) bar() { __asm ("0: b.n 0b"); }
 gives:
<Reset_Handler>:
  push {r3, lr}
  <any-not-need-LR-code>
  bl <bar>

Compiler versions 4_7-2013q3-20130916-win32 thru 5_4-2016q3-20160926-win32 (current)

Revision history for this message
Gary Fuehrer (gfuehrer) wrote :

And, a "b.n" should be emitted, if possible, not a "b.w".

Revision history for this message
Gary Fuehrer (gfuehrer) wrote :

David Brown (https://launchpad.net/~davidbrown) said on 2016-12-02:

Also if you write:

extern void foo(void);
void bar(void)
{
  foo();
  __builtin_unreachable();
}

Then the __builtin_unreachable() causes the "push {r4, lr}" instruction.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.