[LLVMdev] SimplifyCFG vs loops

Chris Lattner clattner at apple.com
Wed Oct 17 09:55:21 PDT 2012


On Oct 17, 2012, at 9:38 AM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:
>>    The current implementation of the CFG simplification is
>>    loop-agnostic. In the past I have observed that it can perform
>>    transformations that can be detrimental to the loop structure.  One
>>    example that I recall, is converting a loop like this:
>>        while (...) {
>>           ...
>>           if (cond) continue;
>>           ...
>>        }
>>    into two nested loops.  Specifically, the "continue" branch would go
>>    back to the loop header making it appear as if there were two back
>>    edges.
>> 
>> 
>> Well, there really are two backedges there.
> 
> There is no reason for two back edges.  This loop could look like this:
> 
> header:
>  ...
>  ...
>  if (cond) goto tail; else goto next;
> next:
>  ...
> tail:
>  if (loop-condition) goto header;
> 
> 
> This way there is one loop with some control flow nested in it, instead of something that looks like two loops.

What problem does that solve?  LLVM's concept of loop is tied to the loop header block: this both forms are a single loop, not two nested loops.

-Chris



More information about the llvm-dev mailing list