summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Constants.cpp19
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp9
2 files changed, 12 insertions, 16 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 0410c758394..aa1d6c909b3 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -184,18 +184,15 @@ bool Constant::isNotMinSignedValue() const {
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
- // Check for constant vectors which are splats of INT_MIN values.
- if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
- if (Constant *Splat = CV->getSplatValue())
- return Splat->isNotMinSignedValue();
-
- // Check for constant vectors which are splats of INT_MIN values.
- if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(this)) {
- if (CV->isSplat()) {
- if (CV->getElementType()->isFloatingPointTy())
- return !CV->getElementAsAPFloat(0).bitcastToAPInt().isMinSignedValue();
- return !CV->getElementAsAPInt(0).isMinSignedValue();
+ // Check that vectors don't contain INT_MIN
+ if (this->getType()->isVectorTy()) {
+ unsigned NumElts = this->getType()->getVectorNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ Constant *Elt = this->getAggregateElement(i);
+ if (!Elt || !Elt->isNotMinSignedValue())
+ return false;
}
+ return true;
}
// It *may* contain INT_MIN, we can't tell.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f0b09e1f0bd..a023b6da232 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2104,11 +2104,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
// ssub.sat(X, C) -> sadd.sat(X, -C) if C != MIN
- // TODO: Support non-splat C.
- const APInt *C;
- if (IID == Intrinsic::ssub_sat && match(Arg1, m_APInt(C)) &&
- !C->isMinSignedValue()) {
- Value *NegVal = ConstantInt::get(II->getType(), -*C);
+ Constant *C;
+ if (IID == Intrinsic::ssub_sat && match(Arg1, m_Constant(C)) &&
+ C->isNotMinSignedValue()) {
+ Value *NegVal = ConstantExpr::getNeg(C);
return replaceInstUsesWith(
*II, Builder.CreateBinaryIntrinsic(
Intrinsic::sadd_sat, Arg0, NegVal));
OpenPOWER on IntegriCloud