[LLVMdev] Is infinite empty loop dead code?

Shuxin Yang shuxin.llvm at gmail.com
Wed Nov 14 00:17:31 PST 2012

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 }

I guess in the gray area, if programmer do not want compiler do 
something he doesn't expect,
he/she perhaps have to resort to some esoteric ways. Compiler would 
otherwise have hard time in

On 11/13/2012 11:46 PM, 陳韋任 (Wei-Ren Chen) wrote:
> On Wed, Nov 14, 2012 at 03:32:53PM +0800, 陳韋任 (Wei-Ren Chen) wrote:
>> On Tue, Nov 13, 2012 at 11:23:02PM -0800, Shuxin Yang wrote:
>>> Hi, All:
>>>       Is it legal to delete empty infinite loop like this : "while(1) {}"?
>>> It is interesting that both llvm and gcc keep the loop, however Open64
>>> delete it.
>>    I think it's illegal to delete such infinite loop, perhapes you should
>> file a bug report to open64. That's my 2 cents.
>    The reason I think it's illegal is because if you remove it, then the
> behavior is different. One with infinite empty loop will run infinitely,
> the other w/o infinite empty loop will exit immediately. That's my
> point.
> Regards,
> chenwj

More information about the llvm-dev mailing list