[llvm-commits] CVS: llvm/lib/VMCore/ConstantHandling.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon May 12 10:27:01 PDT 2003


Changes in directory llvm/lib/VMCore:

ConstantHandling.cpp updated: 1.26 -> 1.27

---
Log message:

Fix Bug: ConstProp/2003-05-12-DivideError.ll


---
Diffs of the changes:

Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.26 llvm/lib/VMCore/ConstantHandling.cpp:1.27
--- llvm/lib/VMCore/ConstantHandling.cpp:1.26	Thu Apr 24 21:52:06 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp	Mon May 12 10:26:25 2003
@@ -461,9 +461,21 @@
   : 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);
   }





More information about the llvm-commits mailing list