https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88343
--- Comment #5 from Iain Sandoe <iains at gcc dot gnu.org> --- I've been trying the following; There were two bugs; 1) the test for Darwin's pic reg needs to be in the save_reg_p () func for other callers. 2) the bit of code in the #ifdef was essentially doing nothing in most cases since Darwin's RS6000_PIC_OFFSET_TABLE_REGNUM is usually (always?) 31. ------ (keeping V4 and Darwin separate in the testing was because there was another option for V4 [ !constant_pool_empty_p () ] to be evaluated). This completed without regression on Power7 (gcc110) and correctly elides the pic reg save for the trivial testcase. Darwin bootstrapped, but testing will take at least 8h so not able to say if that's OK yet. ------- commit cef9f706e794d85afbebc748dbb89541519428c9 Author: Iain Sandoe <i...@sandoe.co.uk> Date: Tue Dec 4 08:01:05 2018 +0000 trial fix for 88343 diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index b5d8584..c296a4a 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -23949,8 +23949,12 @@ save_reg_p (int reg) || !constant_pool_empty_p ())) return true; - if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) - && flag_pic) + if (DEFAULT_ABI == ABI_V4 + && flag_pic && crtl->uses_pic_offset_table) + return true; + + else if (DEFAULT_ABI == ABI_DARWIN + && flag_pic && crtl->uses_pic_offset_table) return true; } @@ -23970,13 +23974,6 @@ first_reg_to_save (void) if (save_reg_p (first_reg)) break; -#if TARGET_MACHO - if (flag_pic - && crtl->uses_pic_offset_table - && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) - return RS6000_PIC_OFFSET_TABLE_REGNUM; -#endif - return first_reg; }