From 5a978b9f8899d6fc42364c0db8ed13b674a5ffb0 Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Thu, 29 Oct 2015 20:27:22 +0100 Subject: [PATCH] rs6000: Save the PIC reg when needed The PIC reg (r30) needs to be saved whenever the prologue sets it up, not just if it is used elsewhere in the function. Without this patch the prologue for such a function will modify r30 without saving it first, leading to disaster back in its callers. This happened in the testsuite for -m32 libgfortran and libstdc++, bootstrapped with -mlra, many hundred times. 2015-10-29 Segher Boessenkool * config/rs6000/rs6000.c (rs6000_reg_live_or_pic_offset_p): Move this function earlier in the file. (first_reg_to_save): Use rs6000_reg_live_or_pic_offset_p instead of df_regs_ever_live_p. From-SVN: r229552 --- gcc/ChangeLog | 7 +++++++ gcc/config/rs6000/rs6000.c | 44 ++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 75ba2e8..50fc56f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2015-10-29 Segher Boessenkool + * config/rs6000/rs6000.c (rs6000_reg_live_or_pic_offset_p): Move this + function earlier in the file. + (first_reg_to_save): Use rs6000_reg_live_or_pic_offset_p instead of + df_regs_ever_live_p. + +2015-10-29 Segher Boessenkool + * lra-constraints.c (process_address_1): Handle (mem:BLK (scratch)) by ignoring it. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 21b4347..bbdd142 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -22016,6 +22016,27 @@ save_reg_p (int r) return !call_used_regs[r] && df_regs_ever_live_p (r); } +/* Determine whether the gp REG is really used. */ + +static bool +rs6000_reg_live_or_pic_offset_p (int reg) +{ + /* If the function calls eh_return, claim used all the registers that would + be checked for liveness otherwise. This is required for the PIC offset + register with -mminimal-toc on AIX, as it is advertised as "fixed" for + register allocation purposes in this case. */ + + return (((crtl->calls_eh_return || df_regs_ever_live_p (reg)) + && (!call_used_regs[reg] + || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM + && !TARGET_SINGLE_PIC_BASE + && TARGET_TOC && TARGET_MINIMAL_TOC))) + || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM + && !TARGET_SINGLE_PIC_BASE + && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) + || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))); +} + /* Return the first fixed-point register that is required to be saved. 32 if none. */ @@ -22033,7 +22054,7 @@ first_reg_to_save (void) && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) || (DEFAULT_ABI == ABI_DARWIN && flag_pic) || (TARGET_TOC && TARGET_MINIMAL_TOC)) - && df_regs_ever_live_p (RS6000_PIC_OFFSET_TABLE_REGNUM)) + && rs6000_reg_live_or_pic_offset_p (RS6000_PIC_OFFSET_TABLE_REGNUM)) first_reg = RS6000_PIC_OFFSET_TABLE_REGNUM; #if TARGET_MACHO @@ -24232,27 +24253,6 @@ rs6000_emit_move_from_cr (rtx reg) emit_insn (gen_movesi_from_cr (reg)); } -/* Determine whether the gp REG is really used. */ - -static bool -rs6000_reg_live_or_pic_offset_p (int reg) -{ - /* If the function calls eh_return, claim used all the registers that would - be checked for liveness otherwise. This is required for the PIC offset - register with -mminimal-toc on AIX, as it is advertised as "fixed" for - register allocation purposes in this case. */ - - return (((crtl->calls_eh_return || df_regs_ever_live_p (reg)) - && (!call_used_regs[reg] - || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM - && !TARGET_SINGLE_PIC_BASE - && TARGET_TOC && TARGET_MINIMAL_TOC))) - || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM - && !TARGET_SINGLE_PIC_BASE - && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) - || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))); -} - /* Return whether the split-stack arg pointer (r12) is used. */ static bool -- 2.7.4