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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216269 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2014-08-22 16:41:23 +00:00
parent 4ef54c3f85
commit 0e4fc41b0d
4 changed files with 38 additions and 1 deletions
+23
View File
@@ -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()) {