diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-07-02 06:07:09 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-07-02 06:07:09 +0000 |
commit | bdeef602e9916ed0b3da64646b91a199adef01e2 (patch) | |
tree | 93214298bb15484298ea6d955989e7a9dd6c1cee /llvm/lib/IR/Constants.cpp | |
parent | 92e87349e0a14e00458b2c1199dbad156d56703a (diff) | |
download | bcm5719-llvm-bdeef602e9916ed0b3da64646b91a199adef01e2.tar.gz bcm5719-llvm-bdeef602e9916ed0b3da64646b91a199adef01e2.zip |
InstCombine: Don't turn -(x/INT_MIN) -> x/INT_MIN
It is not safe to negate the smallest signed integer, doing so yields
the same number back.
This fixes PR20186.
llvm-svn: 212164
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 5851625383b..b815936ac42 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -107,6 +107,28 @@ bool Constant::isAllOnesValue() const { return false; } +bool Constant::isMinSignedValue() 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->isMinSignedValue(); + + // 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->isMinSignedValue(); + + return false; +} + // Constructor to create a '0' constant of arbitrary type... Constant *Constant::getNullValue(Type *Ty) { switch (Ty->getTypeID()) { |