summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-12 15:26:25 +0000
committerChris Lattner <sabre@nondot.org>2003-05-12 15:26:25 +0000
commit893af8c058aad683027c604d6cbe818c59e0eda8 (patch)
treea8a508320f6502373619c1a4a2a2b4a11bdbe68e /lib/VMCore
parent2cfd1aef10b2ed2c39796564459bf585e676e45e (diff)
downloadllvm-893af8c058aad683027c604d6cbe818c59e0eda8.tar.gz
llvm-893af8c058aad683027c604d6cbe818c59e0eda8.tar.bz2
llvm-893af8c058aad683027c604d6cbe818c59e0eda8.tar.xz
Fix Bug: ConstProp/2003-05-12-DivideError.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6125 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/ConstantFold.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 36cc13cf55..8da98f1997 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -461,9 +461,21 @@ struct DirectIntRules
: public DirectRules<ConstantClass, BuiltinType, Ty,
DirectIntRules<ConstantClass, BuiltinType, Ty> > {
+ static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
+ if (V2->isNullValue()) return 0;
+ if (V2->isAllOnesValue() && // MIN_INT / -1
+ (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
+ return 0;
+ BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
+ return ConstantClass::get(*Ty, R);
+ }
+
static Constant *Rem(const ConstantClass *V1,
const ConstantClass *V2) {
- if (V2->isNullValue()) return 0;
+ if (V2->isNullValue()) return 0; // X / 0
+ if (V2->isAllOnesValue() && // MIN_INT / -1
+ (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
+ return 0;
BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
return ConstantClass::get(*Ty, R);
}