[LLVMdev] Inline asm bug?

Eli Friedman eli.friedman at gmail.com
Tue Jan 8 13:52:00 PST 2013

\2013/1/8 Krzysztof Parzyszek <kparzysz at codeaurora.org>:
> Consider this program:
> --- asm.c ---
> int G;
> int foo(char *p) {
>   int rv;
>   G = 0;
>   asm ("" : "=r"(rv)
>           : "r"(p)
>           : "memory");
>   return rv + G;
> }
> -------------
> Is the use of "memory" clobber sufficient to expect the optimizer not to
> optimize the "+ G" away in the return statement?

>From gcc docs: "If your assembler instructions access memory in an
unpredictable fashion, add `memory' to the list of clobbered
registers. This causes GCC to not keep memory values cached in
registers across the assembler instruction and not optimize stores or
loads to that memory. You also should add the volatile keyword if the
memory affected is not listed in the inputs or outputs of the asm, as
the `memory' clobber does not count as a side-effect of the asm. "


More information about the llvm-dev mailing list