]> granicus.if.org Git - llvm/commitdiff
Fix Bug: ConstProp/2003-05-12-DivideError.ll
authorChris Lattner <sabre@nondot.org>
Mon, 12 May 2003 15:26:25 +0000 (15:26 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 12 May 2003 15:26:25 +0000 (15:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6125 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 36cc13cf55024ff3f0247f03befc99723509782b..8da98f19979beb4c2d1f177ceea0aba17a2fdfba 100644 (file)
@@ -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);
   }