[LLVMdev] Is infinite empty loop dead code?

David Blaikie dblaikie at gmail.com
Wed Nov 14 10:05:04 PST 2012


On Wed, Nov 14, 2012 at 9:53 AM, Krzysztof Parzyszek
<kparzysz at codeaurora.org> 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.

Indeed, replacing it with unreachable rather than simply removing it
may provide other optimization opportunities.



More information about the llvm-dev mailing list