[llvm-dev] LoopSimplify pass prevents loop unrolling

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 30 11:54:04 PDT 2017


On 6/30/2017 11:38 AM, Balaram Makam wrote:
>
> Thanks Eli,
>
> I was looking at this code which keeps track of loop headers but is 
> checking if the destination of branch is a loop header sufficient? 
> This prevents merging empty preheaders into the loop headers as well.
>

There isn't really any reason to collapse preheaders anyway; 
LoopSimplify will recreate them, and they don't really block other 
optimizations as far as I know.

> Is that reasonable approach or do we need to skip only if the original 
> unconditional branch was a backedge and folding this branch might 
> result in additional backedges? I made a quick hack to find the 
> function backedges and skip simplifycfg to merge the latch block into 
> the loop header when it results in an additional backedge. Although it 
> solves my purpose I am not sure if this the right approach, as finding 
> the backedges looks expensive.
>

Well, not that expensive to calculate if you cache it, but probably 
tricky to keep the cache up-to-date, yes.

> I also found a regression with this patch where a huge switch 
> statement with multiple empty blocks have been skipped from merging 
> resulting in bad code. Instead, should loopsimplify try to unify 
> multiple exit blocks and collapse multiple backedges whenever possible 
> instead of splitting it out into a nested loop?
>

I'm not sure I follow the issue here.  Could you give an example?

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170630/ddaa931d/attachment.html>


More information about the llvm-dev mailing list