[PATCH] ArgumentPromotion: Don't hack on functions containing musttail calls

Reid Kleckner rnk at google.com
Mon Jun 30 16:23:03 PDT 2014


Hi nlewycky,

The prototypes need to match exactly in order to preserve ABI
guarantees.  Hypothetically, if we can promote both the callee and the
caller all together, we can do argument promotion, but that is a
separable issue.

http://reviews.llvm.org/D4352

Files:
  lib/Transforms/IPO/ArgumentPromotion.cpp
  test/Transforms/ArgumentPromotion/tail.ll

Index: lib/Transforms/IPO/ArgumentPromotion.cpp
===================================================================
--- lib/Transforms/IPO/ArgumentPromotion.cpp
+++ lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -145,7 +145,19 @@
     if (CS.getInstruction()->getParent()->getParent() == F)
       isSelfRecursive = true;
   }
-  
+
+  // Third check: See if this function contains any musttail call sites.  If so,
+  // we can't hack on the calling convention without breaking musttail ABI
+  // guarantees.
+  for (auto CR : *CGN) {
+    Value *Instr = CR.first;
+    CallInst *CS = dyn_cast_or_null<CallInst>(Instr);
+    if (!CS)
+      continue;
+    if (CS->isMustTailCall())
+      return nullptr;
+  }
+
   // Check to see which arguments are promotable.  If an argument is promotable,
   // add it to ArgsToPromote.
   SmallPtrSet<Argument*, 8> ArgsToPromote;
Index: test/Transforms/ArgumentPromotion/tail.ll
===================================================================
--- test/Transforms/ArgumentPromotion/tail.ll
+++ test/Transforms/ArgumentPromotion/tail.ll
@@ -18,3 +18,18 @@
   call void @bar(%pair* byval %Data)
   ret void
 }
+
+; Don't fire on musttail calls, since the calling convention can't be changed.
+declare i8* @musttail_inner(%pair* byval)
+
+define internal i8* @musttail_middle(%pair* byval %Data) {
+; CHECK: define internal i8* @musttail_middle(%pair* byval %Data)
+; CHECK: musttail call i8* @musttail_inner(%pair* byval %Data)
+  %r = musttail call i8* @musttail_inner(%pair* byval %Data)
+  ret i8* %r
+}
+
+define i8* @musttail_outer(%pair* byval %Data) {
+  %r = call i8* @musttail_middle(%pair* byval %Data)
+  ret i8* %r
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4352.10986.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140630/08e7b80d/attachment.bin>


More information about the llvm-commits mailing list