aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/MergeFunctions.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfb@google.com>2015-09-10 18:08:35 +0000
committerJF Bastien <jfb@google.com>2015-09-10 18:08:35 +0000
commitfa946233b4e1ad857ecc4b14cec1f31c40eb94fa (patch)
tree3205853dcc4e35bd98bb4a7b5f360da8325337fd /llvm/lib/Transforms/IPO/MergeFunctions.cpp
parenta7970f3cf8eb0f3b2f46081aec7be0b70dfe5692 (diff)
downloadllvm-fa946233b4e1ad857ecc4b14cec1f31c40eb94fa.zip
llvm-fa946233b4e1ad857ecc4b14cec1f31c40eb94fa.tar.gz
llvm-fa946233b4e1ad857ecc4b14cec1f31c40eb94fa.tar.bz2
[MergeFuncs] Fix callsite attributes in thunk generation
This change correctly sets the attributes on the callsites generated in thunks. This makes sure things such as sret, sext, etc. are correctly set, so that the call can be a proper tailcall. Also, the transfer of attributes in the replaceDirectCallers function appears to be unnecessary, but until this is confirmed it will remain. Author: jrkoenig Reviewers: dschuff, jfb Subscribers: llvm-commits, nlewycky Differential revision: http://reviews.llvm.org/D12581 llvm-svn: 247313
Diffstat (limited to 'llvm/lib/Transforms/IPO/MergeFunctions.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index fa6c4ea..a8a85982 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -1559,9 +1559,16 @@ void MergeFunctions::replaceDirectCallers(Function *Old, Function *New) {
CallSite CS(U->getUser());
if (CS && CS.isCallee(U)) {
// Transfer the called function's attributes to the call site. Due to the
- // bitcast we will 'loose' ABI changing attributes because the 'called
+ // bitcast we will 'lose' ABI changing attributes because the 'called
// function' is no longer a Function* but the bitcast. Code that looks up
// the attributes from the called function will fail.
+
+ // FIXME: This is not actually true, at least not anymore. The callsite
+ // will always have the same ABI affecting attributes as the callee,
+ // because otherwise the original input has UB. Note that Old and New
+ // always have matching ABI, so no attributes need to be changed.
+ // Transferring other attributes may help other optimizations, but that
+ // should be done uniformly and not in this ad-hoc way.
auto &Context = New->getContext();
auto NewFuncAttrs = New->getAttributes();
auto CallSiteAttrs = CS.getAttributes();
@@ -1656,6 +1663,7 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
CallInst *CI = Builder.CreateCall(F, Args);
CI->setTailCall();
CI->setCallingConv(F->getCallingConv());
+ CI->setAttributes(F->getAttributes());
if (NewG->getReturnType()->isVoidTy()) {
Builder.CreateRetVoid();
} else {