summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-12-01 10:58:34 +0000
committerNikita Popov <nikita.ppv@gmail.com>2018-12-01 10:58:34 +0000
commit0c5d6ccbfc089b3335a78d910febff44c3dd622c (patch)
tree3e286d283381129ed31af749e6144b4d36b8ca92 /llvm/lib/IR/Constants.cpp
parent958b94d6791a345e2221ee4291cb209a7ec579ba (diff)
downloadbcm5719-llvm-0c5d6ccbfc089b3335a78d910febff44c3dd622c.tar.gz
bcm5719-llvm-0c5d6ccbfc089b3335a78d910febff44c3dd622c.zip
[InstCombine] Support ssub.sat canonicalization for non-splats
Extend ssub.sat(X, C) -> sadd.sat(X, -C) canonicalization to also support non-splat vector constants. This is done by generalizing the implementation of the isNotMinSignedValue() helper to return true for constants that are non-splat, but don't contain any signed min elements. Differential Revision: https://reviews.llvm.org/D55011 llvm-svn: 348072
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp19
1 files changed, 8 insertions, 11 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.
OpenPOWER on IntegriCloud