[PATCH] ArgumentPromotion: Don't hack on functions containing musttail calls
Reid Kleckner
rnk at google.com
Mon Jun 30 16:25:03 PDT 2014
- Add an assert near the tail call removal that I found
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;
@@ -816,6 +828,7 @@
CallInst *Call = dyn_cast<CallInst>(U);
if (!Call)
continue;
+ assert(!Call->isMustTailCall());
Call->setTailCall(false);
}
continue;
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.10987.patch
Type: text/x-patch
Size: 1880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140630/df26e5c9/attachment.bin>
More information about the llvm-commits
mailing list