aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index c7fb848802..63cd256dc5 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -6048,7 +6048,15 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
CallSite::arg_iterator AI = CS.arg_begin();
for (unsigned i = 0, e = NumCommonArgs; i != e; ++i, ++AI) {
const Type *ParamTy = FT->getParamType(i);
- bool isConvertible = (*AI)->getType()->isLosslesslyConvertibleTo(ParamTy);
+ const Type *ActTy = (*AI)->getType();
+ ConstantSInt* c = dyn_cast<ConstantSInt>(*AI);
+ //Either we can cast directly, or we can upconvert the argument
+ bool isConvertible = ActTy->isLosslesslyConvertibleTo(ParamTy) ||
+ (ParamTy->isIntegral() && ActTy->isIntegral() &&
+ ParamTy->isSigned() == ActTy->isSigned() &&
+ ParamTy->getPrimitiveSize() >= ActTy->getPrimitiveSize()) ||
+ (c && ParamTy->getPrimitiveSize() >= ActTy->getPrimitiveSize() &&
+ c->getValue() > 0);
if (Callee->isExternal() && !isConvertible) return false;
}