PING [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]

Segher Boessenkool segher@kernel.crashing.org
Mon Sep 14 23:20:32 GMT 2020


Hi!

On Fri, Sep 11, 2020 at 05:24:58PM -0500, Qing Zhao wrote:
> > So IMO the pass should just search for all the
> > returns in a function and insert the zeroing instructions before
> > each one.
> 
> I was considering this approach too for some time, however, there is one major issue with this as 
> Segher mentioned, The middle end does not know some details on the registers, lacking such 
> detailed information might result incorrect code generation at middle end.
> 
> For example, on x86_64 target, when “return” with pop, the scratch register “ECX” will be 
> used for returning, then it’s incorrect to zero “ecx” before generating the return. Since middle end
> doesn't have such information, it cannot avoid to zero “ecx”. Therefore incorrect code might be 
> generated. 
> 
> Segher also mentioned that on Power, there are some scratch registers also are used for 
> Other purpose, clearing them before return is not correct. 

Depending where you insert those insns, it can be non-harmful, but in
most places it will not be useful.


What you can do (easy and safe) is change the RTL return instructions to
clear all necessary registers (by outputting extra assembler
instructions).  I still have big doubts how effective that will be, and
esp. compared with how expensive that is, but at least its effect on the
compiler is very local, and it does not get in the way of most things.

(This also works with shrink-wrapping and similar.)

(The effectiveness of this whole scheme depends a *lot* on specifics of
the ABI, btw; in that way it is not generic at all!)


Segher


More information about the Gcc-patches mailing list