diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-27 05:39:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-27 05:39:41 +0000 |
commit | c6b3b25f940ac4abe376f98e15d10c4e4e583e55 (patch) | |
tree | f0aee80d479de05167dad3fd300c4f2034efe74e /llvm/lib/Transforms/Utils/InlineFunction.cpp | |
parent | 58ee24c8bfbcd8a77fc7787b3bfc715cae9e3516 (diff) | |
download | bcm5719-llvm-c6b3b25f940ac4abe376f98e15d10c4e4e583e55.tar.gz bcm5719-llvm-c6b3b25f940ac4abe376f98e15d10c4e4e583e55.zip |
Fix a pretty serious misfeature of the inliner: if it inlines a function
with multiple return values it inserts a PHI to merge them all together.
However, if the return values are all the same, it ends up with a pointless
PHI and this pointless PHI happens to really block SRoA from happening in
at least a silly C++ example written by Doug, but probably others. This
fixes rdar://7339069.
llvm-svn: 85206
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/InlineFunction.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 619c939064d..20f5a4a9423 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -619,8 +619,17 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD, "Ret value not consistent in function!"); PHI->addIncoming(RI->getReturnValue(), RI->getParent()); } + + // Now that we inserted the PHI, check to see if it has a single value + // (e.g. all the entries are the same or undef). If so, remove the PHI so + // it doesn't block other optimizations. + if (Value *V = PHI->hasConstantValue()) { + PHI->replaceAllUsesWith(V); + PHI->eraseFromParent(); + } } + // Add a branch to the merge points and remove return instructions. for (unsigned i = 0, e = Returns.size(); i != e; ++i) { ReturnInst *RI = Returns[i]; |