On Tue, Sep 30, 2014 at 8:00 AM, Jiong Wang <jiong.w...@arm.com> wrote: > On 27/09/14 22:20, Kugan wrote: >> >> >> On 23/09/14 01:58, Jiong Wang wrote: >>> >>> On 22/09/14 16:43, Kugan wrote: >>> >>>> AArch64 has the same issue ARM had where the LR register was not used in >>>> leaf functions. This was reported in >>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42017. In AArch64, this >>>> test-case need to be added with more live ranges for the need for the >>>> LR_REGNUM. i.e test-case in the PR needs additional loops up to r31 for >>>> the case AArch64 to see this. >>>> >>>> The same fix (from the thread >>>> https://gcc.gnu.org/ml/gcc-patches/2011-04/msg02191.html) which went >>>> into ARM should apply to AArch64 as well. Regression tested on qemu for >>>> aarch64-none-linux-gnu with no new regressions. Is this OK for trunk? >>> >>> This still be a partial fix. LR should be a caller-saved register free >>> to use in case it's saved properly to across function call. >> >> Indeed. This should be improved from the generic code. Right now, if a >> hard register is used in EPILOGUE_USES, it conflicts with all the live >> ranges till a call site kills. I think we should have this patch till >> the generic code can be improved. > > > below is my local patch. LR is treated as free register, and strictly > following AArch64 ABI, frame should always be created, FP maintained > properly if LR clobbered under -fno-omit-frame-pointer. > > > gcc/ > * config/aarch64/aarch64.h (CALL_USED_REGISTERS): Mark LR as caller-save. > (EPILOGUE_USES): Guard the check by epilogue_completed. > * config/aarch64/aarch64.c (aarch64_layout_frame): Explictly check for LR. > (aarch64_can_eliminate): Check LR_REGNUM liveness. > > gcc/testsuite/ > * gcc.target/aarch64/lr_free_1.c: New testcase for -fomit-frame-pointer. > * gcc.target/aarch64/lr_free_2.c: New testcase for leaf > -fno-omit-frame-pointer.
+ /* If we decided that we didn't need a leaf frame pointer but then used + LR in the function, then we'll want a frame pointer after all, so + prevent this elimination to ensure a frame pointer is used. */ + if (to == STACK_POINTER_REGNUM + && flag_omit_leaf_frame_pointer + && df_regs_ever_live_p (LR_REGNUM)) + return false; This breaks my build on aarch64-elf (with some local modifications) as aarch64_frame_pointer_required returns true but then we use LR but now aarch64_can_eliminate and aarch64_frame_pointer_required are inconsitant which is not a valid thing for LRA (and reload). This was mentioned in https://gcc.gnu.org/ml/gcc-patches/2013-12/msg00151.html : " IRA calls hook frame_pointer_required and it returns false. After that LRA calls can_eliminate hook and it returns false which means that fp can not be used for allocation and we should spill all pseudos assigned to it." Can you revert your patch until you can figure out how to get LRA (and reload) to play nicely with what you want to do? Thanks, Andrew Pinski