[llvm-commits] [SignlessTypes] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Instructions.cpp

Reid Spencer reid at x10sys.com
Wed Oct 25 18:58:37 PDT 2006



Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.93.2.8 -> 1.93.2.9
Constants.cpp updated: 1.163.2.9 -> 1.163.2.10
Instructions.cpp updated: 1.42.2.6 -> 1.42.2.7
---
Log message:

Round 2 of DIV updates. 


---
Diffs of the changes:  (+73 -22)

 ConstantFolding.cpp |   28 ++++++++++++----------------
 Constants.cpp       |   34 ++++++++++++++++++++++++++++++----
 Instructions.cpp    |   33 +++++++++++++++++++++++++++++++--
 3 files changed, 73 insertions(+), 22 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.8 llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.9
--- llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.8	Mon Oct 23 13:13:27 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Wed Oct 25 20:58:05 2006
@@ -531,30 +531,27 @@
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
         (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue())
       return 0;
-    BuiltinType R = 
-      (BuiltinType)V1->getZExtValue() / (BuiltinType)V2->getZExtValue();
+    BuiltinType R = BuiltinType(V1->getZExtValue() / V2->getZExtValue());
     return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *URem(const ConstantInt *V1,
-                        const ConstantInt *V2) {
-    if (V2->isNullValue()) return 0;         // X / 0
+  static Constant *SDiv(const ConstantInt *V1, const ConstantInt *V2) {
+    if (V2->isNullValue()) 
+      return 0;
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
-        (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue())
+        (BuiltinType)V1->getSExtValue() == -(BuiltinType)V1->getSExtValue())
       return 0;
-    BuiltinType R = 
-      (BuiltinType)V1->getZExtValue() % (BuiltinType)V2->getZExtValue();
+    BuiltinType R = BuiltinType(V1->getSExtValue() / V2->getSExtValue());
     return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *SDiv(const ConstantInt *V1, const ConstantInt *V2) {
-    if (V2->isNullValue()) 
-      return 0;
+  static Constant *URem(const ConstantInt *V1,
+                        const ConstantInt *V2) {
+    if (V2->isNullValue()) return 0;         // X / 0
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
-        (BuiltinType)V1->getSExtValue() == -(BuiltinType)V1->getSExtValue())
+        (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue())
       return 0;
-    BuiltinType R = 
-      (BuiltinType)V1->getSExtValue() / (BuiltinType)V2->getSExtValue();
+    BuiltinType R = BuiltinType(V1->getZExtValue() % V2->getZExtValue());
     return ConstantInt::get(*Ty, R);
   }
 
@@ -564,8 +561,7 @@
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
         (BuiltinType)V1->getSExtValue() == -(BuiltinType)V1->getSExtValue())
       return 0;
-    BuiltinType R = 
-      (BuiltinType)V1->getSExtValue() % (BuiltinType)V2->getSExtValue();
+    BuiltinType R = BuiltinType(V1->getSExtValue() % V2->getSExtValue());
     return ConstantInt::get(*Ty, R);
   }
 


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.163.2.9 llvm/lib/VMCore/Constants.cpp:1.163.2.10
--- llvm/lib/VMCore/Constants.cpp:1.163.2.9	Mon Oct 23 13:13:27 2006
+++ llvm/lib/VMCore/Constants.cpp	Wed Oct 25 20:58:05 2006
@@ -1421,15 +1421,41 @@
 Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
 #ifndef NDEBUG
   switch (Opcode) {
-  case Instruction::Add: case Instruction::Sub:
-  case Instruction::URem: case Instruction::SRem: case Instruction::FRem:
-  case Instruction::Mul: case Instruction::UDiv: 
-  case Instruction::SDiv: case Instruction::FDiv:
+  case Instruction::Add: 
+  case Instruction::Sub:
+  case Instruction::Mul: 
     assert(C1->getType() == C2->getType() && "Op types should be identical!");
     assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint() ||
             isa<PackedType>(C1->getType())) &&
            "Tried to create an arithmetic operation on a non-arithmetic type!");
     break;
+  case Instruction::UDiv: 
+  case Instruction::SDiv: 
+    assert(C1->getType() == C2->getType() && "Op types should be identical!");
+    assert((C1->getType()->isInteger() || (isa<PackedType>(C1->getType()) &&
+      cast<PackedType>(C1->getType())->getElementType()->isInteger())) &&
+           "Tried to create an arithmetic operation on a non-arithmetic type!");
+    break;
+  case Instruction::FDiv:
+    assert(C1->getType() == C2->getType() && "Op types should be identical!");
+    assert((C1->getType()->isFloatingPoint() || (isa<PackedType>(C1->getType())
+      && cast<PackedType>(C1->getType())->getElementType()->isFloatingPoint())) 
+      && "Tried to create an arithmetic operation on a non-arithmetic type!");
+    break;
+  case Instruction::URem: 
+  case Instruction::SRem: 
+    assert(C1->getType() == C2->getType() && "Op types should be identical!");
+    assert((C1->getType()->isInteger() || (isa<PackedType>(C1->getType()) &&
+      cast<PackedType>(C1->getType())->getElementType()->isInteger())) &&
+           "Tried to create an arithmetic operation on a non-arithmetic type!");
+    break;
+  case Instruction::FRem:
+    assert(C1->getType() == C2->getType() && "Op types should be identical!");
+    assert((C1->getType()->isFloatingPoint() || (isa<PackedType>(C1->getType())
+      && cast<PackedType>(C1->getType())->getElementType()->isFloatingPoint())) 
+      && "Tried to create an arithmetic operation on a non-arithmetic type!");
+    break;
+
   case Instruction::And:
   case Instruction::Or:
   case Instruction::Xor:


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.42.2.6 llvm/lib/VMCore/Instructions.cpp:1.42.2.7
--- llvm/lib/VMCore/Instructions.cpp:1.42.2.6	Mon Oct 23 13:13:27 2006
+++ llvm/lib/VMCore/Instructions.cpp	Wed Oct 25 20:58:05 2006
@@ -1022,14 +1022,43 @@
 #ifndef NDEBUG
   switch (iType) {
   case Add: case Sub:
-  case URem: case SRem: case FRem:
-  case Mul: case UDiv: case SDiv: case FDiv:
+  case Mul: 
     assert(getType() == LHS->getType() &&
            "Arithmetic operation should return same type as operands!");
     assert((getType()->isInteger() || getType()->isFloatingPoint() ||
             isa<PackedType>(getType())) &&
           "Tried to create an arithmetic operation on a non-arithmetic type!");
     break;
+  case UDiv: 
+  case SDiv: 
+    assert(getType() == LHS->getType() &&
+           "Arithmetic operation should return same type as operands!");
+    assert((getType()->isInteger() || (isa<PackedType>(getType()) && 
+            cast<PackedType>(getType())->getElementType()->isInteger())) &&
+           "Incorrect operand type (not integer) for S/UDIV");
+    break;
+  case FDiv:
+    assert(getType() == LHS->getType() &&
+           "Arithmetic operation should return same type as operands!");
+    assert((getType()->isFloatingPoint() || (isa<PackedType>(getType()) &&
+            cast<PackedType>(getType())->getElementType()->isFloatingPoint())) 
+            && "Incorrect operand type (not floating point) for FDIV");
+    break;
+  case URem: 
+  case SRem: 
+    assert(getType() == LHS->getType() &&
+           "Arithmetic operation should return same type as operands!");
+    assert((getType()->isInteger() || (isa<PackedType>(getType()) && 
+            cast<PackedType>(getType())->getElementType()->isInteger())) &&
+           "Incorrect operand type (not integer) for S/UREM");
+    break;
+  case FRem:
+    assert(getType() == LHS->getType() &&
+           "Arithmetic operation should return same type as operands!");
+    assert((getType()->isFloatingPoint() || (isa<PackedType>(getType()) &&
+            cast<PackedType>(getType())->getElementType()->isFloatingPoint())) 
+            && "Incorrect operand type (not floating point) for FREM");
+    break;
   case And: case Or:
   case Xor:
     assert(getType() == LHS->getType() &&






More information about the llvm-commits mailing list