summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-07 22:54:13 +0000
committerChris Lattner <sabre@nondot.org>2003-10-07 22:54:13 +0000
commit6c266db54cb2a3ddcce49ce8cc8c334292d58a3a (patch)
tree4dfa3dd8acdc4f5292e35d6847332d9a9b4d5a77 /lib/Transforms
parentd1c5ea1071bc2f794974bf1f4720d262fe668550 (diff)
downloadllvm-6c266db54cb2a3ddcce49ce8cc8c334292d58a3a.tar.gz
llvm-6c266db54cb2a3ddcce49ce8cc8c334292d58a3a.tar.bz2
llvm-6c266db54cb2a3ddcce49ce8cc8c334292d58a3a.tar.xz
Fix bug: InstCombine/cast.ll:test11 / PR#7
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8954 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index b31ec635c8..8188929cd5 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1607,10 +1607,32 @@ static const Type *getPromotedType(const Type *Ty) {
// visitCallSite - Improvements for call and invoke instructions.
//
Instruction *InstCombiner::visitCallSite(CallSite CS) {
+ bool Changed = false;
+
+ // If the callee is a constexpr cast of a function, attempt to move the cast
+ // to the arguments of the call/invoke.
if (transformConstExprCastCall(CS)) return 0;
+ Value *Callee = CS.getCalledValue();
+ const PointerType *PTy = cast<PointerType>(Callee->getType());
+ const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
+ if (FTy->isVarArg()) {
+ // See if we can optimize any arguments passed through the varargs area of
+ // the call.
+ for (CallSite::arg_iterator I = CS.arg_begin()+FTy->getNumParams(),
+ E = CS.arg_end(); I != E; ++I)
+ if (CastInst *CI = dyn_cast<CastInst>(*I)) {
+ // If this cast does not effect the value passed through the varargs
+ // area, we can eliminate the use of the cast.
+ Value *Op = CI->getOperand(0);
+ if (CI->getType()->isLosslesslyConvertibleTo(Op->getType())) {
+ *I = Op;
+ Changed = true;
+ }
+ }
+ }
- return 0;
+ return Changed ? CS.getInstruction() : 0;
}
// transformConstExprCastCall - If the callee is a constexpr cast of a function,