On Thu, Feb 01, 2024 at 10:15:30AM -0800, H.J. Lu wrote: > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -22749,6 +22749,31 @@ current_fentry_section (const char **name) > return true; > } > > +/* Return an unused caller-saved register at entry for profile. */ > + > +static int > +x86_64_select_profile_regnum (bool r11_ok ATTRIBUTE_UNUSED) > +{ > + int i;
Why not just return R10_REG here if flag_entry != 0 (i.e. keep existing behavior unless emitting profiler after prologue)? > + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) > + if (GENERAL_REGNO_P (i) > +#ifdef NO_PROFILE_COUNTERS > + && (r11_ok || i != R11_REG) > +#else > + && i != R11_REG > +#endif > + && (!REX2_INT_REGNO_P (i) || TARGET_APX_EGPR) > + && !fixed_regs[i] > + && call_used_regs[i] > + && !df_regs_ever_live_p (i)) Also, isn't this too restrictive? I mean, all we care about is whether there is some register which is not live across the NOTE_INSN_PROLOG_END note, no? I.e. doesn't contain any of function's argument that are used later, and isn't set in the prologue to be used later. E.g. call used register which is just saved to stack in the prologue might be just fine. > + return i; > + > + sorry ("No register available for profiling %<-mcmodel=large%s%>", Diagnostics shouldn't start with capital letter. > + ix86_cmodel == CM_LARGE_PIC ? " -fPIC" : ""); > + > + return INVALID_REGNUM; > +} > + > /* Output assembler code to FILE to increment profiler label # LABELNO > for profiling a function entry. */ > void Jakub