[LLVMdev] Separating loop nests based on profile information?

Krzysztof Parzyszek kparzysz at codeaurora.org
Mon Jan 12 11:00:48 PST 2015


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

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation



More information about the llvm-dev mailing list