Problem understand optimization with inline asm
Segher Boessenkool
segher@kernel.crashing.org
Tue Mar 28 22:45:45 GMT 2023
Hi!
On Tue, Mar 28, 2023 at 12:15:37PM +0100, Kalamatee via Gcc-help wrote:
> Now, I can work around this by using "+" (even though I don't read the
> variable), or initializing the value a second time in the asm block - but
> should I have to? This sounds like the compiler is doing the wrong thing
> based on the assertion/assumption "=" means I will 100% change some
> variable,
Yes, that is what an output contraint means. From the manual:
'='
Means that this operand is written to by this instruction: the
previous value is discarded and replaced by new data.
If you use "+" it will mean exactly what you want. "+" means "both an
input and an output operand".
'+'
Means that this operand is both read and written by the
instruction.
If you want the asm to have semantics like
if (cond)
x = y;
this can be equivalently written as
if (cond)
x = y;
else
x = x;
or maybe even
x = (cond) ? y : x;
and written that way it is clear you really want an in/out constraint
here :-)
HtH,
Segher
More information about the Gcc-help
mailing list