https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125266
--- Comment #12 from Richard Sandiford <rsandifo at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #11)
> (In reply to Richard Sandiford from comment #10)
> > > If I understand it correctly, call_used_regs only describes registers
> > > clobbered
> > > by callee and it shouldn't be used for anything else.
> > Yeah. Specifically by callees that use the default ABI.
>
> The default ABI is vague. What is the default ABI when a file compiled
> with GPRs only at the command-line? What is the default ABI when a target
> attribute on a function enables SSE registers which aren't enabled at
> the command-line?
Like I think you imply below, the default is effectively "what you would get if
this target was selected on the command line and if a function had no
attributes".
There might be some cases ("interrupt"?) that change both the set of available
registers and whether the remaining available registers are call-used, but as
the internals go, that's logically two separate things.
> > > If a target attribute
> > > enables additional registers in a function, shouldn't callee's
> > > call_used_regs
> > > in such a function be different, i.e., clobber more registers? Also a
> > > target
> > > attribute may reduce number of registers in a function, like GPRs only.
> > > How
> > > does call_used_regs work in these cases?
> > I suppose it depends on why the register is fixed. Some targets have
> > special-purpose fixed registers that are call-preserved rather than
> > call-used. And some targets have fixed registers that are effectively
> > global (like the FP rounding mode). But if a register isn't being used at
> > all (like SIMD registers when only GPRs are enabled), then the normal
> > approach is to treat the register as call-used.
>
> I got ICE when I marked x87 registers as call-used while X87 is disabled
> at the command-line.
Ah, ok. Maybe stack registers are different? I don't really know about those.
But isn't that what ix86_conditional_register_usage already does? Or am I
misreading it? It looks like CALL_USED_REGISTERS initialises the stack
registers to 1, and:
/* If the FPU is disabled, disable the registers. */
if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
accessible_reg_set &= ~reg_class_contents[FLOAT_REGS];
disables them without changing call_used_regs.
> > The function_abi definitions are a property of the current target, rather
> > than global. So if ix86_set_current_function treated "GPR only" as a
> > separate target, that target would also get its own set of specialised
> > function_abis. Setting up the target would indirectly call
> > ix86_conditional_register_usage.
> >
> > If we did that, the "GPR only" version of the no_caller_saved_registers ABI
> > would preserve only GPRs, while the "normal" version of the
> > no_caller_saved_registers ABI would preserve SIMD registers. But like I
> > say, it would all happen "naturally" through ix86_set_current_target
> > changing target.
>
> When compiling a function, call_used_regs applies to the default ABI.
> "default" here means that if a callee doesn't have attribute, the callee
> will use the same call_used_regs as caller.
No, not the same as the caller. E.g. if a preserves_none function F1 calls a
function F2 that has no attributes, F2 preserves the normal set of registers.
F2 has the "default" ABI and F1 has the preserves_none ABI. The same is true
if F2 calls F1.
That is: if F1 and F2 have the same target, the definition of "default" doesn't
vary depending on whether F1 or F2 is the caller. The default is the same for
both.