[LLVMdev] Is infinite empty loop dead code?

Shuxin Yang shuxin.llvm at gmail.com
Wed Nov 14 10:07:49 PST 2012


If the code is unreachable, such code is easy to be removed, and should 
be removed.

If it is reachable, that is bit difficult to tell. Now that C std 
already give compiler such permit,
perhaps we don't have to keep in sync with gcc. Otherwise, it is very 
difficult to delete dead
non-countable loop.

One might argue, do you see many dead non-countable loops?
I don't know the answer, but in the case I'm working on the loop was not 
dead at beginning,
but after I recognize some idiom and remove some statements out of the 
loop. Then the loop becomes dead.
I hope DCE to get rid of it.

On 11/14/12 9:53 AM, Krzysztof Parzyszek wrote:
> On 11/14/2012 1:23 AM, Shuxin Yang wrote:
>>
>>      Is it legal to delete empty infinite loop like this : "while(1) 
>> {}"?
>
> If the loop was reachable, the program will not terminate.  If you 
> delete the loop, where is the execution going to go after this point? 
> You can't arbitrarily insert a branch to somewhere or instructions to 
> execute.  If the loop was unreachable, then it doesn't matter if you 
> delete it or not unless you want to reduce code size, but regardless 
> of that, if you can prove that it's unreachable then you can delete it 
> as such and then it doesn't matter what it does.
>
> -Krzysztof
>
>
>




More information about the llvm-dev mailing list