[PATCH] D53588: [hot-cold-split] split more than a cold region per function

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 23 11:22:40 PDT 2018


vsk added a comment.

In https://reviews.llvm.org/D53588#1272789, @vsk wrote:

> @sebpop thanks for this patch! I don't see any problems with it (although I would prefer that the test explicitly check that outlined functions contain the correct instructions).
>
> At a higher-level, I'm seeing some problems with the forward/back cold propagation done in getHotBlocks on internal projects. The propagation seems to stop when it encounters simple control flow, like an if-then-else or a for loop, after which cold code is unconditionally executed.


Btw, here's an example. ToT does not outline given this code:

  extern void sideeffect(int);
  
  extern void __attribute__((noreturn)) sink();
  
  void foo(int cond) {
    if (cond) {
      while (cond > 10) {
        --cond;
        sideeffect(0);
      }
  
      sink();
    }
  
    sideeffect(1);
  }

With my prototype, the loop may be outlined:

  Outlined Region:
  ; Function Attrs: minsize nounwind optsize ssp uwtable
  define internal void @__outlined_foo_if.then(i32 %cond) #3 {
  newFuncRoot:
    br label %if.then
  
  if.then:                                          ; preds = %newFuncRoot
    %cmp3 = icmp sgt i32 %cond, 10
    br i1 %cmp3, label %while.body.preheader, label %while.end
  
  while.body.preheader:                             ; preds = %if.then
    br label %while.body
  
  while.body:                                       ; preds = %while.body.preheader, %while.body
    %cond.addr.04 = phi i32 [ %dec, %while.body ], [ %cond, %while.body.preheader ]
    %dec = add nsw i32 %cond.addr.04, -1
    tail call void @sideeffect(i32 0) #4
    %cmp = icmp sgt i32 %cond.addr.04, 11
    br i1 %cmp, label %while.body, label %while.end.loopexit
  
  while.end.loopexit:                               ; preds = %while.body
    br label %while.end
  
  while.end:                                        ; preds = %while.end.loopexit, %if.then
    tail call void (...) @sink() #5
    unreachable
  }
  HotColdSplitting: Outlined 12 insts



> I have a prototype of a different propagation scheme which overcomes some of these limitations. The idea is to mark blocks which are post-dominated by a cold block, or are dominated by a cold block, as cold. This is able to handle the control flow I described, and isn't limited to requiring a single exit block. Could you give me a day to evaluate it further, run benchmarks etc. and report back? If it turns out to be promising, istm that it'd make sense to rebase this patch on top of it.


https://reviews.llvm.org/D53588





More information about the llvm-commits mailing list