[PATCH] D39137: Add CallSiteSplitting pass

Jun Bum Lim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 12:31:52 PDT 2017


junbuml created this revision.
Herald added subscribers: kristof.beyls, mehdi_amini, mgorny, aemerson.

This change add a pass which tries to split a call-site to pass
more constrained arguments if its argument is predicated in the control flow
so that we can expose better context to the later passes (e.g, inliner, jump
threading, or IPA-CP based function cloning, etc.).
As of now we support two cases :

1. If a call site is dominated by an OR condition and if any of its arguments

are predicated on this OR condition, try to split the condition with more
constrained arguments. For example, in the code below, we try to split the
call site since we can predicate the argument (ptr) based on the OR condition.

Split from :

  if (!ptr || c)
    callee(ptr);

to :

  if (!ptr)
    callee(nonnull ptr)  // set non-null attribute in the argument
  else if (c)
    callee(null)               // set the known constant value

2. We can also split a call-site based on constant incoming values of a PHI

For example,
from :

  BB0:
   %c = icmp eq i32 %i1, %i2
   br i1 %c, label %BB2, label %BB1
  BB1:
   br label %BB2
  BB2:
   %p = phi i32 [ 0, %BB0 ], [ 1, %BB1 ]
   call void @bar(i32 %p)

to

  BB0:
   %c = icmp eq i32 %i1, %i2
   br i1 %c, label %BB2-split0, label %BB1
  BB1:
   br label %BB2-split1
  BB2-split0:
   call void @bar(i32 0)
   br label %BB2
  BB2-split1:
   call void @bar(i32 1)
   br label %BB2
  BB2:
   %p = phi i32 [ 0, %BB2-split0 ], [ 1, %BB2-split1 ]

Enabled this for https://reviews.llvm.org/owners/package/3/  and  LTO. I didn't see any significant code size increase in my spec2000/2006/2017 tests on aarch64. Observed 20% performance gain in spec2017/gcc without regressions in other benchmarks.

I've added only two simple tests to demonstrate this pass, but I will add more
tests covering what this patch doing if the overall approach is reasonable.


https://reviews.llvm.org/D39137

Files:
  include/llvm/InitializePasses.h
  include/llvm/Transforms/Scalar.h
  include/llvm/Transforms/Scalar/CallSiteSplitting.h
  lib/Passes/PassBuilder.cpp
  lib/Passes/PassRegistry.def
  lib/Transforms/IPO/PassManagerBuilder.cpp
  lib/Transforms/Scalar/CMakeLists.txt
  lib/Transforms/Scalar/CallSiteSplitting.cpp
  lib/Transforms/Scalar/Scalar.cpp
  test/Other/new-pm-defaults.ll
  test/Other/new-pm-lto-defaults.ll
  test/Other/new-pm-thinlto-defaults.ll
  test/Transforms/CallSiteSplitting/callsite-split.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39137.119685.patch
Type: text/x-patch
Size: 28044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171020/e9013208/attachment.bin>


More information about the llvm-commits mailing list