diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-08-22 16:41:23 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-22 16:41:23 +0000 |
commit | 0e6c98669661347727fa13414e7046afaad565bd (patch) | |
tree | 6b88ad1e92ef861458f52560732c15f5f402e71f /llvm/lib/IR/Constants.cpp | |
parent | 5117674f55a7d9f4359cf1ad9f1591db9997b231 (diff) | |
download | bcm5719-llvm-0e6c98669661347727fa13414e7046afaad565bd.tar.gz bcm5719-llvm-0e6c98669661347727fa13414e7046afaad565bd.zip |
InstCombine: sub nsw %x, C -> add nsw %x, -C if C isn't INT_MIN
We can preserve nsw during this transform if -C won't overflow.
llvm-svn: 216269
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index b72d850ce25..e2db4fdb291 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -151,6 +151,29 @@ bool Constant::isMinSignedValue() const { return false; } +bool Constant::isNotMinSignedValue() const { + // Check for INT_MIN integers + if (const ConstantInt *CI = dyn_cast<ConstantInt>(this)) + return !CI->isMinValue(/*isSigned=*/true); + + // Check for FP which are bitcasted from INT_MIN integers + 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 (Constant *Splat = CV->getSplatValue()) + return Splat->isNotMinSignedValue(); + + // It *may* contain INT_MIN, we can't tell. + return false; +} + // Constructor to create a '0' constant of arbitrary type... Constant *Constant::getNullValue(Type *Ty) { switch (Ty->getTypeID()) { |