[proposed 4.7 fix for ARM PR42017, I swapped the condition to avoid loading a global variable unnecessarily ] Date: Thu, 28 Apr 2011 11:13:49 +0800 From: Chung-Lin Tang Subject: [patch, ARM] Fix PR42017, LR not used in leaf functions List-Archive: Hi, this patch tries to solve the problem of the LR register not being used in leaf functions on ARM. Looking at the dumps, it shows that register 14 (lr) conflicts with all allocnos throughout the entire leaf procedure. A little digging shows that lr is present in the OBJECT_CONFLICT_HARD_REGS() set of all allocnos, which suggests that this may manifest from a convention of some sort the code is currently following. It turns out that, during the IRA liveness computations, the DF initing of live hard regs, starting from the bottom end of the function, adds EPILOGUE_USES right from the start. With no call sites to kill its liveness, the entire procedure is prohibited from using LR at all. This problem may also be more serious than just leaf functions. Theoretically, this may affect all allocnos that happen to completely lie on paths that reach the end of function without a call site, even in non-leaf functions. All these are deprived of LR as an usable register. My fix here simply adds 'reload_completed' as an additional condition for EPILOGUE_USES to return true for LR_REGNUM. I think this should be valid, as correct LR save/restoring is handled by the epilogue/prologue code; it should be safe for IRA to treat it as a normal call-used register. I did a cross-test on QEMU with clean results, plus a successful native bootstrap on a Pandaboard. Is this okay for trunk? Thanks, Chung-Lin 2011-04-28 Chung-Lin Tang PR target/42017 * config/arm/arm.h (EPILOGUE_USES): Only return true for LR_REGNUM after reload_completed. --- gcc-4.6.2/gcc/config/arm/arm.h.~1~ 2011-07-14 23:26:01.000000000 +0200 +++ gcc-4.6.2/gcc/config/arm/arm.h 2011-12-10 21:24:56.000000000 +0100 @@ -1658,7 +1658,7 @@ typedef struct frame. */ #define EXIT_IGNORE_STACK 1 -#define EPILOGUE_USES(REGNO) ((REGNO) == LR_REGNUM) +#define EPILOGUE_USES(REGNO) ((REGNO) == LR_REGNUM && reload_completed) /* Determine if the epilogue should be output as RTL. You should override this if you define FUNCTION_EXTRA_EPILOGUE. */