summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-14 06:06:08 +0000
committerChris Lattner <sabre@nondot.org>2004-01-14 06:06:08 +0000
commit1f7942fe7d66e3fc9ee2044adb1a2eef1a3437d4 (patch)
tree7d93442f2d8f848ea03cc49734622e15103986a6 /llvm/lib/Transforms
parent1c0133ffd99a583394ba89c956d93155d7bcf741 (diff)
downloadbcm5719-llvm-1f7942fe7d66e3fc9ee2044adb1a2eef1a3437d4.tar.gz
bcm5719-llvm-1f7942fe7d66e3fc9ee2044adb1a2eef1a3437d4.zip
Fix InstCombine/2004-01-13-InstCombineInvokePHI.ll, which also fixes lots
of C++ programs in Shootout-C++, including lists1 and moments, etc llvm-svn: 10845
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 14e2c70a8c9..bc9558e8db1 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1821,10 +1821,26 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
const FunctionType *FT = Callee->getFunctionType();
const Type *OldRetTy = Caller->getType();
- if (Callee->isExternal() &&
- !OldRetTy->isLosslesslyConvertibleTo(FT->getReturnType()) &&
- !Caller->use_empty())
- return false; // Cannot transform this return value...
+ // Check to see if we are changing the return type...
+ if (OldRetTy != FT->getReturnType()) {
+ if (Callee->isExternal() &&
+ !OldRetTy->isLosslesslyConvertibleTo(FT->getReturnType()) &&
+ !Caller->use_empty())
+ return false; // Cannot transform this return value...
+
+ // If the callsite is an invoke instruction, and the return value is used by
+ // a PHI node in a successor, we cannot change the return type of the call
+ // because there is no place to put the cast instruction (without breaking
+ // the critical edge). Bail out in this case.
+ if (!Caller->use_empty())
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Caller))
+ for (Value::use_iterator UI = II->use_begin(), E = II->use_end();
+ UI != E; ++UI)
+ if (PHINode *PN = dyn_cast<PHINode>(*UI))
+ if (PN->getParent() == II->getNormalDest() ||
+ PN->getParent() == II->getExceptionalDest())
+ return false;
+ }
unsigned NumActualArgs = unsigned(CS.arg_end()-CS.arg_begin());
unsigned NumCommonArgs = std::min(FT->getNumParams(), NumActualArgs);
OpenPOWER on IntegriCloud