PROPOSAL: Extend inline asm syntax with size spec

Segher Boessenkool segher@kernel.crashing.org
Sun Oct 7 13:23:00 GMT 2018


On Sun, Oct 07, 2018 at 11:18:06AM +0200, Borislav Petkov wrote:
> this is an attempt to see whether gcc's inline asm heuristic when
> estimating inline asm statements' cost for better inlining can be
> improved.

GCC already estimates the *size* of inline asm, and this is required
*for correctness*.  So any workaround that works against this will only
end in tears.

Taking size as an estimate of cost is not very good.  But in your
motivating example you actually *do* care mostly about size, namely, for
the inlining decisions.

So I guess the real issue is that the inline asm size estimate for x86
isn't very good (since it has to be pessimistic, and x86 insns can be
huge)?

> Now, Richard suggested doing something like:
> 
>  1) inline asm ("...")

What would the semantics of this be?

>  2) asm ("..." : : : : <size-expr>)

This potentially conflicts with the syntax for asm goto.

>  3) asm ("...") __attribute__((asm_size(<size-expr>)));

Eww.

> with which user can tell gcc what the size of that inline asm statement
> is and thus allow for more precise cost estimation and in the end better
> inlining.

More precise *size* estimates, yes.  And if the user lies he should not
be surprised to get assembler errors, etc.

> And FWIW 3) looks pretty straight-forward to me because attributes are
> pretty common anyways.

I don't like 2) either.  But 1) looks interesting, depends what its
semantics would be?  "Don't count this insn's size for inlining decisions",
maybe?


Another option is to just force inlining for those few functions where
GCC currently makes an inlining decision you don't like.  Or are there
more than a few?


Segher



More information about the Gcc mailing list