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

Reid Spencer reid at x10sys.com
Sun Oct 22 01:59:31 PDT 2006



Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.93.2.5 -> 1.93.2.6
Constants.cpp updated: 1.163.2.7 -> 1.163.2.8
Instruction.cpp updated: 1.53.2.3 -> 1.53.2.4
Instructions.cpp updated: 1.42.2.4 -> 1.42.2.5
---
Log message:

Implement the FDIV instruction for floating point divide.


---
Diffs of the changes:  (+26 -11)

 ConstantFolding.cpp |   25 +++++++++++++++++--------
 Constants.cpp       |    6 +++++-
 Instruction.cpp     |    4 +++-
 Instructions.cpp    |    2 +-
 4 files changed, 26 insertions(+), 11 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.5 llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.6
--- llvm/lib/VMCore/ConstantFolding.cpp:1.93.2.5	Fri Oct 20 03:01:26 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Sun Oct 22 03:59:01 2006
@@ -42,6 +42,7 @@
     virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0;
     virtual Constant *udiv(const Constant *V1, const Constant *V2) const = 0;
     virtual Constant *sdiv(const Constant *V1, const Constant *V2) const = 0;
+    virtual Constant *fdiv(const Constant *V1, const Constant *V2) const = 0;
     virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0;
     virtual Constant *op_and(const Constant *V1, const Constant *V2) const = 0;
     virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0;
@@ -113,6 +114,9 @@
   virtual Constant *sdiv(const Constant *V1, const Constant *V2) const {
     return SubClassName::SDiv((const ArgType *)V1, (const ArgType *)V2);
   }
+  virtual Constant *fdiv(const Constant *V1, const Constant *V2) const {
+    return SubClassName::FDiv((const ArgType *)V1, (const ArgType *)V2);
+  }
   virtual Constant *rem(const Constant *V1, const Constant *V2) const {
     return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
   }
@@ -187,6 +191,7 @@
   static Constant *Mul (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *SDiv(const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *UDiv(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *FDiv(const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *Rem (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *And (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *Or  (const ArgType *V1, const ArgType *V2) { return 0; }
@@ -384,6 +389,9 @@
   static Constant *SDiv(const ConstantPacked *V1, const ConstantPacked *V2) {
     return EvalVectorOp(V1, V2, ConstantExpr::getSDiv);
   }
+  static Constant *FDiv(const ConstantPacked *V1, const ConstantPacked *V2) {
+    return EvalVectorOp(V1, V2, ConstantExpr::getFDiv);
+  }
   static Constant *Rem(const ConstantPacked *V1, const ConstantPacked *V2) {
     return EvalVectorOp(V1, V2, ConstantExpr::getRem);
   }
@@ -635,14 +643,7 @@
                                    (BuiltinType)V2->getValue());
     return ConstantFP::get(*Ty, Result);
   }
-  static Constant *UDiv(const ConstantFP *V1, const ConstantFP *V2) {
-    BuiltinType inf = std::numeric_limits<BuiltinType>::infinity();
-    if (V2->isExactlyValue(0.0)) return ConstantFP::get(*Ty, inf);
-    if (V2->isExactlyValue(-0.0)) return ConstantFP::get(*Ty, -inf);
-    BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
-    return ConstantFP::get(*Ty, R);
-  }
-  static Constant *SDiv(const ConstantFP *V1, const ConstantFP *V2) {
+  static Constant *FDiv(const ConstantFP *V1, const ConstantFP *V2) {
     BuiltinType inf = std::numeric_limits<BuiltinType>::infinity();
     if (V2->isExactlyValue(0.0)) return ConstantFP::get(*Ty, inf);
     if (V2->isExactlyValue(-0.0)) return ConstantFP::get(*Ty, -inf);
@@ -1253,6 +1254,7 @@
   case Instruction::Mul:     C = ConstRules::get(V1, V2).mul(V1, V2); break;
   case Instruction::UDiv:    C = ConstRules::get(V1, V2).udiv(V1, V2); break;
   case Instruction::SDiv:    C = ConstRules::get(V1, V2).sdiv(V1, V2); break;
+  case Instruction::FDiv:    C = ConstRules::get(V1, V2).fdiv(V1, V2); break;
   case Instruction::Rem:     C = ConstRules::get(V1, V2).rem(V1, V2); break;
   case Instruction::And:     C = ConstRules::get(V1, V2).op_and(V1, V2); break;
   case Instruction::Or:      C = ConstRules::get(V1, V2).op_or (V1, V2); break;
@@ -1337,6 +1339,7 @@
       return Constant::getNullValue(V1->getType());
     case Instruction::UDiv:
     case Instruction::SDiv:
+    case Instruction::FDiv:
     case Instruction::Rem:
       if (!isa<UndefValue>(V2))     // undef/X -> 0
         return Constant::getNullValue(V1->getType());
@@ -1393,6 +1396,11 @@
           if (CI->getZExtValue() == 1)
             return const_cast<Constant*>(V1);                     // X / 1 == X
         break;
+      case Instruction::FDiv:
+        if (const ConstantFP* CFP = dyn_cast<ConstantFP>(V2))     // X / 1.0 == X
+          if (CFP->getValue() == 1.0)
+            return const_cast<Constant*>(V1);
+        break;
       case Instruction::Rem:
         if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2))
           if (CI->getZExtValue() == 1)
@@ -1451,6 +1459,7 @@
     case Instruction::Sub:
     case Instruction::SDiv:
     case Instruction::UDiv:
+    case Instruction::FDiv:
     case Instruction::Rem:
     default:  // These instructions cannot be flopped around.
       break;


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.163.2.7 llvm/lib/VMCore/Constants.cpp:1.163.2.8
--- llvm/lib/VMCore/Constants.cpp:1.163.2.7	Fri Oct 20 02:41:24 2006
+++ llvm/lib/VMCore/Constants.cpp	Sun Oct 22 03:59:01 2006
@@ -425,6 +425,9 @@
 Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2) {
   return get(Instruction::SDiv, C1, C2);
 }
+Constant *ConstantExpr::getFDiv(Constant *C1, Constant *C2) {
+  return get(Instruction::FDiv, C1, C2);
+}
 Constant *ConstantExpr::getRem(Constant *C1, Constant *C2) {
   return get(Instruction::Rem, C1, C2);
 }
@@ -1413,7 +1416,8 @@
 #ifndef NDEBUG
   switch (Opcode) {
   case Instruction::Add: case Instruction::Sub:
-  case Instruction::Mul: case Instruction::UDiv: case Instruction::SDiv:
+  case Instruction::Mul: case Instruction::UDiv: 
+  case Instruction::SDiv: case Instruction::FDiv:
   case Instruction::Rem:
     assert(C1->getType() == C2->getType() && "Op types should be identical!");
     assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint() ||


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.53.2.3 llvm/lib/VMCore/Instruction.cpp:1.53.2.4
--- llvm/lib/VMCore/Instruction.cpp:1.53.2.3	Thu Oct 19 23:27:18 2006
+++ llvm/lib/VMCore/Instruction.cpp	Sun Oct 22 03:59:01 2006
@@ -96,6 +96,7 @@
   case Mul: return "mul";
   case UDiv: return "udiv";
   case SDiv: return "sdiv";
+  case FDiv: return "fdiv";
   case Rem: return "rem";
 
   // Logical operators...
@@ -222,8 +223,9 @@
 ///
 bool Instruction::isTrapping(unsigned op) {
   switch(op) {
-  case SDiv:
   case UDiv:
+  case SDiv:
+  case FDiv:
   case Rem:
   case Load:
   case Store:


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.42.2.4 llvm/lib/VMCore/Instructions.cpp:1.42.2.5
--- llvm/lib/VMCore/Instructions.cpp:1.42.2.4	Thu Oct 19 23:27:18 2006
+++ llvm/lib/VMCore/Instructions.cpp	Sun Oct 22 03:59:01 2006
@@ -1022,7 +1022,7 @@
 #ifndef NDEBUG
   switch (iType) {
   case Add: case Sub:
-  case Mul: case UDiv: case SDiv:
+  case Mul: case UDiv: case SDiv: case FDiv:
   case Rem:
     assert(getType() == LHS->getType() &&
            "Arithmetic operation should return same type as operands!");






More information about the llvm-commits mailing list