[LLVMdev] Is infinite empty loop dead code?

Joerg Sonnenberger joerg at britannica.bec.de
Wed Nov 14 04:39:52 PST 2012


On Wed, Nov 14, 2012 at 12:17:31AM -0800, Shuxin Yang wrote:
> Following loop (in asm) is often seen in embedded programs. It is
> used to delay for certain amount of time.
> If it were not written in asm, compiler would blindly delete the
> entire loop. How can compiler know such DCE
> betray program intention?
>    for (i = 0; i < N; i++) { nop; nop; nop }

The canonical example of doing this in a safe way is to touch a volatile
variable.

Joerg



More information about the llvm-dev mailing list