[PATCH] D13764: [LoopUnswitch] Spill unswitch quota based on branch weight

Chen Li via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 22:22:55 PDT 2015


chenli created this revision.
chenli added reviewers: reames, davidxl.
chenli added a subscriber: llvm-commits.

This patch teaches LoopUnswitch to spill unswitch quota to old loop and newly generated loop based on branch weight. 

Consider the following example 


```
for (...)
   if (cond1) 
     dummy1()
   else
     dummy2()
   if (cond2)
     dummy3()
   else
     break
```

This loop can be unswitched twice based on cond1 and cond2, ending with 4 loops if we have enough quota. However, if we dont have enough quota, we should spend most of them on the hot branch based on branch weight. In this example, if the branch to dummy1() is hotter than dummy2(), we should give the quota to loop with dummy1() and end up with:


```
 if (cond1)
   if (cond2)
     for (...)
       dummy1()
       dummy3()
   else
     for (...)
       dummy1()
       break
 else
   for (...) 
     dummy2()
     if (cond2)
       dummy3()
     else
       break
```

If we don't spill quota based on branch weight, the colder branch will get unswitched and not help performance.

http://reviews.llvm.org/D13764

Files:
  lib/Transforms/Scalar/LoopUnswitch.cpp
  test/Transforms/LoopUnswitch/unswitch-with-branch-weight.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13764.37445.patch
Type: text/x-patch
Size: 9406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151015/2b2932e1/attachment.bin>


More information about the llvm-commits mailing list