https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89775
Bug ID: 89775 Summary: Stackpointer save/restore instructions optimized away Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: krebbel at gcc dot gnu.org Target Milestone: --- Defining the stack pointer register as global register triggers wrong code to be generated thanks to bug in the prologue/epilogue optimization. In this case the prologue save instruction for the stack pointer is removed while the epilogue insn is kept. So r15 will be restored from f0 and hence loaded with garbage. register a __asm__("15"); b() { char c = 0; } b: ldgr %f2,%r11 lay %r15,-168(%r15) lgr %r11,%r15 mvi 167(%r11),0 lr 0,0 lgr %r2,%r1 lgdr %r11,%f2 lgdr %r15,%f0 br %r14 Even if a global register is being clobbered in a function we usually do not save and restore it. However, we still have to do this if it is a special register. Most of the places in the backend handle this correctly but not the prologue/epilogue optimization. A fix is being tested and will be available soon.