[LLVMdev] Separating loop nests based on profile information?

Philip Reames listmail at philipreames.com
Mon Jan 19 17:57:42 PST 2015


This is correct.  JumpThreading would pretty much undo this 
transformation.  Oddly, SimplifyCFG does not, even though it probably 
could (and possible should.)

Philip

On 01/12/2015 11:40 AM, Krzysztof Parzyszek wrote:
> Upon closer inspection, the loop will not become irreducible.  
> However, the result will be equivalent to reloading the hoisted values 
> after calling "helper".  In fact, that's what may happen if some CFG 
> optimization cleans this up.
>
> -Krzysztof
>
>
> On 1/12/2015 1:00 PM, Krzysztof Parzyszek wrote:
>> On 1/7/2015 7:19 PM, Philip Reames wrote:
>>>
>>> The approach I've been playing with would create this loop structure:
>>> goto inner
>>> while (true) {
>>>    outer:
>>>    helper();
>>>    inner:
>>>    while( some_condition )
>>>      //do lots of work here
>>>      if (!some_rare_condition) { <-- This is loop variant
>>>        goto outer;
>>>      }
>>>    }
>>> }
>>>
>>
>> Anything that changes loop structure into something like this, is a
>> fundamentally bad idea.  This would make the outer loop irreducible,
>> which should be avoided.
>>
>> A lot better approach would be to privatize the invariant objects, and
>> write them back to memory before/after the "helper" is invoked:
>>
>>      T1 = p->x;
>>      T2 = P->y;
>>      while( some_condition )
>>        //do lots of work here, use T1 and T2
>>        if (some_rare_condition) { <-- This is loop variant
>>          p->x = T1;
>>          p->y = T2;
>>          helper();
>>          T1 = p->x;
>>          T2 = p->y;
>>        }
>>      }
>>      p->x = T1;
>>      p->y = T2;
>>
>>
>> -Krzysztof
>>
>
>




More information about the llvm-dev mailing list