[PATCH] D43729: [CallSiteSplitting] do not split musttail calls

Fedor Indutny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 23:09:39 PST 2018


indutny created this revision.
indutny added reviewers: junbuml, mcrosier, davidxl, davide.

`musttail` calls can't be naively splitted. The split blocks must
include not only the call instruction itself, but also (optional)
bitcast and return instructions that follow it.

---

I've tried to implement it in a proper way, but it doesn't seem to work from the first try. Any hints appreciated!

Here's what I've tried so far: https://gist.github.com/indutny/240c33522563ebd633613a903479d5e6 . It seems to be broken in many ways that I don't yet understand.


Repository:
  rL LLVM

https://reviews.llvm.org/D43729

Files:
  lib/Transforms/Scalar/CallSiteSplitting.cpp
  test/Transforms/CallSiteSplitting/musttail.ll


Index: test/Transforms/CallSiteSplitting/musttail.ll
===================================================================
--- /dev/null
+++ test/Transforms/CallSiteSplitting/musttail.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -callsite-splitting -S
+
+define i8* @caller(i8* %a, i8* %b) {
+  %c = icmp eq i8* %a, null
+  br i1 %c, label %Tail, label %TBB
+TBB:
+  %c2 = icmp eq i8* %b, null
+  br i1 %c2, label %Tail, label %End
+Tail:
+  %ca = musttail call i8* @callee(i8* %a, i8* %b)
+  %cb = bitcast i8* %ca to i8*
+  ret i8* %cb
+End:
+  ret i8* null
+}
+
+define i8* @callee(i8* %a, i8* %b) noinline {
+  ret i8* %a
+}
Index: lib/Transforms/Scalar/CallSiteSplitting.cpp
===================================================================
--- lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -397,6 +397,14 @@
 static bool tryToSplitCallSite(CallSite CS, TargetTransformInfo &TTI) {
   if (!CS.arg_size() || !canSplitCallSite(CS, TTI))
     return false;
+
+  // musttail calls can't be naively splitted. The split blocks must include
+  // not only the call instruction itself, but also (optional) bitcast and
+  // return instructions that follow it.
+  //
+  // TODO: Implement proper splitting
+  if (CS.isMustTailCall())
+    return false;
   return tryToSplitOnPredicatedArgument(CS) ||
          tryToSplitOnPHIPredicatedArgument(CS);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43729.135787.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180224/b4638cf3/attachment.bin>


More information about the llvm-commits mailing list