For PR970:
Clean up handling of isFloatingPoint() and dealing with PackedType.
Patch by Gordon Henriksen!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33415 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/docs/LangRef.html b/docs/LangRef.html
index c423c0b..4b71ba3 100644
--- a/docs/LangRef.html
+++ b/docs/LangRef.html
@@ -2867,7 +2867,7 @@
 
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
-   <a name="i_fp2uint">'<tt>fptoui .. to</tt>' Instruction</a>
+   <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
 </div>
 <div class="doc_text">
 
@@ -3270,9 +3270,6 @@
   <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
   <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
 </ol>
-<p>If the operands are <a href="#t_packed">packed</a> typed, the elements of 
-the vector are compared in turn and the predicate must hold for all elements.
-</p>
 
 <h5>Example:</h5>
 <pre>  &lt;result&gt; = fcmp oeq float 4.0, 5.0    <i>; yields: result=false</i>
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h
index 80e0a9d..fad2da9 100644
--- a/include/llvm/Analysis/ScalarEvolutionExpander.h
+++ b/include/llvm/Analysis/ScalarEvolutionExpander.h
@@ -60,8 +60,7 @@
     /// loop (inserting one if there is none).  A canonical induction variable
     /// starts at zero and steps by one on each iteration.
     Value *getOrInsertCanonicalInductionVariable(const Loop *L, const Type *Ty){
-      assert((Ty->isInteger() || Ty->isFloatingPoint()) &&
-             "Can only insert integer or floating point induction variables!");
+      assert(Ty->isInteger() && "Can only insert integer induction variables!");
       SCEVHandle H = SCEVAddRecExpr::get(SCEVUnknown::getIntegerSCEV(0, Ty),
                                          SCEVUnknown::getIntegerSCEV(1, Ty), L);
       return expand(H);
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 5a17f39..c92229e 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -36,7 +36,7 @@
 struct ConvertConstantType;
 
 //===----------------------------------------------------------------------===//
-/// This is the shared class of boolean and integrer constants. This class 
+/// This is the shared class of boolean and integer constants. This class 
 /// represents both boolean and integral constants.
 /// @brief Class for constant integers.
 class ConstantInt : public Constant {
@@ -585,6 +585,11 @@
   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
 
+  /// Floating point negation must be implemented with f(x) = -0.0 - x. This
+  /// method returns the negative zero constant for floating point or packed
+  /// floating point types; for all other types, it returns the null value.
+  static Constant *getZeroValueForNegationExpr(const Type *Ty);
+
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return false; }
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
index f0acbcb..97e9b5f 100644
--- a/include/llvm/Support/PatternMatch.h
+++ b/include/llvm/Support/PatternMatch.h
@@ -306,37 +306,6 @@
 //
 
 template<typename LHS_t>
-struct neg_match {
-  LHS_t L;
-
-  neg_match(const LHS_t &LHS) : L(LHS) {}
-
-  template<typename OpTy>
-  bool match(OpTy *V) {
-    if (Instruction *I = dyn_cast<Instruction>(V))
-      if (I->getOpcode() == Instruction::Sub)
-        return matchIfNeg(I->getOperand(0), I->getOperand(1));
-    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
-      if (CE->getOpcode() == Instruction::Sub)
-        return matchIfNeg(CE->getOperand(0), CE->getOperand(1));
-    if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
-      return L.match(ConstantExpr::getNeg(CI));
-    return false;
-  }
-private:
-  bool matchIfNeg(Value *LHS, Value *RHS) {
-    if (!LHS->getType()->isFloatingPoint())
-      return LHS == Constant::getNullValue(LHS->getType()) && L.match(RHS);
-    else
-      return LHS == ConstantFP::get(LHS->getType(), -0.0) && L.match(RHS);
-  }
-};
-
-template<typename LHS>
-inline neg_match<LHS> m_Neg(const LHS &L) { return L; }
-
-
-template<typename LHS_t>
 struct not_match {
   LHS_t L;
 
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index e9e7e79..3d985ab 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -123,8 +123,7 @@
 
     // Insert a unit add instruction right before the terminator corresponding
     // to the back-edge.
-    Constant *One = Ty->isFloatingPoint() ? (Constant*)ConstantFP::get(Ty, 1.0)
-                                          : ConstantInt::get(Ty, 1);
+    Constant *One = ConstantInt::get(Ty, 1);
     Instruction *Add = BinaryOperator::createAdd(PN, One, "indvar.next",
                                                  (*HPI)->getTerminator());
 
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index e8d5845..bf16327 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -499,32 +499,37 @@
   void visitInvoke(InvokeInst &I) { assert(0 && "TODO"); }
   void visitUnwind(UnwindInst &I) { assert(0 && "TODO"); }
 
-  void visitIntBinary(User &I, unsigned IntOp, unsigned VecOp);
-  void visitFPBinary(User &I, unsigned FPOp, unsigned VecOp);
+  void visitScalarBinary(User &I, unsigned OpCode);
+  void visitVectorBinary(User &I, unsigned OpCode);
+  void visitEitherBinary(User &I, unsigned ScalarOp, unsigned VectorOp);
   void visitShift(User &I, unsigned Opcode);
   void visitAdd(User &I) { 
-    if (I.getType()->isFloatingPoint())
-      visitFPBinary(I, ISD::FADD, ISD::VADD); 
+    if (isa<PackedType>(I.getType()))
+      visitVectorBinary(I, ISD::VADD);
+    else if (I.getType()->isFloatingPoint())
+      visitScalarBinary(I, ISD::FADD);
     else
-      visitIntBinary(I, ISD::ADD, ISD::VADD); 
+      visitScalarBinary(I, ISD::ADD);
   }
   void visitSub(User &I);
   void visitMul(User &I) {
-    if (I.getType()->isFloatingPoint()) 
-      visitFPBinary(I, ISD::FMUL, ISD::VMUL); 
+    if (isa<PackedType>(I.getType()))
+      visitVectorBinary(I, ISD::VMUL);
+    else if (I.getType()->isFloatingPoint())
+      visitScalarBinary(I, ISD::FMUL);
     else
-      visitIntBinary(I, ISD::MUL, ISD::VMUL); 
+      visitScalarBinary(I, ISD::MUL);
   }
-  void visitURem(User &I) { visitIntBinary(I, ISD::UREM, 0); }
-  void visitSRem(User &I) { visitIntBinary(I, ISD::SREM, 0); }
-  void visitFRem(User &I) { visitFPBinary (I, ISD::FREM, 0); }
-  void visitUDiv(User &I) { visitIntBinary(I, ISD::UDIV, ISD::VUDIV); }
-  void visitSDiv(User &I) { visitIntBinary(I, ISD::SDIV, ISD::VSDIV); }
-  void visitFDiv(User &I) { visitFPBinary (I, ISD::FDIV, ISD::VSDIV); }
-  void visitAnd(User &I) { visitIntBinary(I, ISD::AND, ISD::VAND); }
-  void visitOr (User &I) { visitIntBinary(I, ISD::OR,  ISD::VOR); }
-  void visitXor(User &I) { visitIntBinary(I, ISD::XOR, ISD::VXOR); }
-  void visitShl(User &I) { visitShift(I, ISD::SHL); }
+  void visitURem(User &I) { visitScalarBinary(I, ISD::UREM); }
+  void visitSRem(User &I) { visitScalarBinary(I, ISD::SREM); }
+  void visitFRem(User &I) { visitScalarBinary(I, ISD::FREM); }
+  void visitUDiv(User &I) { visitEitherBinary(I, ISD::UDIV, ISD::VUDIV); }
+  void visitSDiv(User &I) { visitEitherBinary(I, ISD::SDIV, ISD::VSDIV); }
+  void visitFDiv(User &I) { visitEitherBinary(I, ISD::FDIV, ISD::VSDIV); }
+  void visitAnd (User &I) { visitEitherBinary(I, ISD::AND,  ISD::VAND ); }
+  void visitOr  (User &I) { visitEitherBinary(I, ISD::OR,   ISD::VOR  ); }
+  void visitXor (User &I) { visitEitherBinary(I, ISD::XOR,  ISD::VXOR ); }
+  void visitShl (User &I) { visitShift(I, ISD::SHL); }
   void visitLShr(User &I) { visitShift(I, ISD::SRL); }
   void visitAShr(User &I) { visitShift(I, ISD::SRA); }
   void visitICmp(User &I);
@@ -1369,46 +1374,47 @@
 
 void SelectionDAGLowering::visitSub(User &I) {
   // -0.0 - X --> fneg
-  if (I.getType()->isFloatingPoint()) {
+  const Type *Ty = I.getType();
+  if (isa<PackedType>(Ty)) {
+    visitVectorBinary(I, ISD::VSUB);
+  } else if (Ty->isFloatingPoint()) {
     if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0)))
       if (CFP->isExactlyValue(-0.0)) {
         SDOperand Op2 = getValue(I.getOperand(1));
         setValue(&I, DAG.getNode(ISD::FNEG, Op2.getValueType(), Op2));
         return;
       }
-    visitFPBinary(I, ISD::FSUB, ISD::VSUB);
+    visitScalarBinary(I, ISD::FSUB);
   } else 
-    visitIntBinary(I, ISD::SUB, ISD::VSUB);
+    visitScalarBinary(I, ISD::SUB);
 }
 
-void 
-SelectionDAGLowering::visitIntBinary(User &I, unsigned IntOp, unsigned VecOp) {
-  const Type *Ty = I.getType();
+void SelectionDAGLowering::visitScalarBinary(User &I, unsigned OpCode) {
   SDOperand Op1 = getValue(I.getOperand(0));
   SDOperand Op2 = getValue(I.getOperand(1));
-
-  if (const PackedType *PTy = dyn_cast<PackedType>(Ty)) {
-    SDOperand Num = DAG.getConstant(PTy->getNumElements(), MVT::i32);
-    SDOperand Typ = DAG.getValueType(TLI.getValueType(PTy->getElementType()));
-    setValue(&I, DAG.getNode(VecOp, MVT::Vector, Op1, Op2, Num, Typ));
-  } else {
-    setValue(&I, DAG.getNode(IntOp, Op1.getValueType(), Op1, Op2));
-  }
+  
+  setValue(&I, DAG.getNode(OpCode, Op1.getValueType(), Op1, Op2));
 }
 
-void 
-SelectionDAGLowering::visitFPBinary(User &I, unsigned FPOp, unsigned VecOp) {
-  const Type *Ty = I.getType();
-  SDOperand Op1 = getValue(I.getOperand(0));
-  SDOperand Op2 = getValue(I.getOperand(1));
+void
+SelectionDAGLowering::visitVectorBinary(User &I, unsigned OpCode) {
+  assert(isa<PackedType>(I.getType()));
+  const PackedType *Ty = cast<PackedType>(I.getType());
+  SDOperand Typ = DAG.getValueType(TLI.getValueType(Ty->getElementType()));
 
-  if (const PackedType *PTy = dyn_cast<PackedType>(Ty)) {
-    SDOperand Num = DAG.getConstant(PTy->getNumElements(), MVT::i32);
-    SDOperand Typ = DAG.getValueType(TLI.getValueType(PTy->getElementType()));
-    setValue(&I, DAG.getNode(VecOp, MVT::Vector, Op1, Op2, Num, Typ));
-  } else {
-    setValue(&I, DAG.getNode(FPOp, Op1.getValueType(), Op1, Op2));
-  }
+  setValue(&I, DAG.getNode(OpCode, MVT::Vector,
+                           getValue(I.getOperand(0)),
+                           getValue(I.getOperand(1)),
+                           DAG.getConstant(Ty->getNumElements(), MVT::i32),
+                           Typ));
+}
+
+void SelectionDAGLowering::visitEitherBinary(User &I, unsigned ScalarOp,
+                                             unsigned VectorOp) {
+  if (isa<PackedType>(I.getType()))
+    visitVectorBinary(I, VectorOp);
+  else
+    visitScalarBinary(I, ScalarOp);
 }
 
 void SelectionDAGLowering::visitShift(User &I, unsigned Opcode) {
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 41d7aad..2ddfc97 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1498,7 +1498,7 @@
   const IntegerType *SITy = cast<IntegerType>(SrcTy);
   unsigned SBitWidth = SITy->getBitWidth();
   assert(SBitWidth <= 64  && "Integer types > 64 bits not supported");
-  assert(DstTy->isFloatingPoint() && "Invalid UIToFP instruction");
+  assert(DstTy->isFloatingPoint() && "Invalid SIToFP instruction");
   int64_t Converted = 0;
   if (SBitWidth == 1)
     Converted = 0LL - Src.Int1Val;
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index 1ed804e..ee5549b 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -576,8 +576,8 @@
       // Can convert store if the incoming value is convertible and if the
       // result will preserve semantics...
       const Type *Op0Ty = I->getOperand(0)->getType();
-      if (!(Op0Ty->isInteger() ^ ElTy->isInteger()) &&
-          !(Op0Ty->isFloatingPoint() ^ ElTy->isFloatingPoint()))
+      if (Op0Ty->isInteger() == ElTy->isInteger() &&
+          Op0Ty->isFloatingPoint() == ElTy->isFloatingPoint())
         return ExpressionConvertibleToType(I->getOperand(0), ElTy, CTMap, TD);
     }
     return false;
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index bbf5241..d9ba12c 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1343,6 +1343,7 @@
       if (Constant *SOVConstant = dyn_cast<Constant>(GS.StoredOnceValue))
         if (GV->getType()->getElementType() != Type::Int1Ty &&
             !GV->getType()->getElementType()->isFloatingPoint() &&
+            !isa<PackedType>(GV->getType()->getElementType()) &&
             !GS.HasPHIUser) {
           DOUT << "   *** SHRINKING TO BOOL: " << *GV;
           ShrinkGlobalToBoolean(GV, SOVConstant);
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index 287bff2..4fcbf35 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -186,11 +186,7 @@
 /// LowerNegateToMultiply - Replace 0-X with X*-1.
 ///
 static Instruction *LowerNegateToMultiply(Instruction *Neg) {
-  Constant *Cst;
-  if (Neg->getType()->isFloatingPoint())
-    Cst = ConstantFP::get(Neg->getType(), -1);
-  else
-    Cst = ConstantInt::getAllOnesValue(Neg->getType());
+  Constant *Cst = ConstantInt::getAllOnesValue(Neg->getType());
 
   std::string NegName = Neg->getName(); Neg->setName("");
   Instruction *Res = BinaryOperator::createMul(Neg->getOperand(1), Cst, NegName,
@@ -661,32 +657,32 @@
     std::map<Value*, unsigned> FactorOccurrences;
     unsigned MaxOcc = 0;
     Value *MaxOccVal = 0;
-    if (!I->getType()->isFloatingPoint()) {
-      for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
-        if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Ops[i].Op))
-          if (BOp->getOpcode() == Instruction::Mul && BOp->use_empty()) {
-            // Compute all of the factors of this added value.
-            std::vector<Value*> Factors;
-            FindSingleUseMultiplyFactors(BOp, Factors);
-            assert(Factors.size() > 1 && "Bad linearize!");
-            
-            // Add one to FactorOccurrences for each unique factor in this op.
-            if (Factors.size() == 2) {
-              unsigned Occ = ++FactorOccurrences[Factors[0]];
-              if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[0]; }
-              if (Factors[0] != Factors[1]) {   // Don't double count A*A.
-                Occ = ++FactorOccurrences[Factors[1]];
-                if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[1]; }
+    for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
+      if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Ops[i].Op)) {
+        if (BOp->getOpcode() == Instruction::Mul && BOp->use_empty()) {
+          // Compute all of the factors of this added value.
+          std::vector<Value*> Factors;
+          FindSingleUseMultiplyFactors(BOp, Factors);
+          assert(Factors.size() > 1 && "Bad linearize!");
+
+          // Add one to FactorOccurrences for each unique factor in this op.
+          if (Factors.size() == 2) {
+            unsigned Occ = ++FactorOccurrences[Factors[0]];
+            if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[0]; }
+            if (Factors[0] != Factors[1]) {   // Don't double count A*A.
+              Occ = ++FactorOccurrences[Factors[1]];
+              if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[1]; }
+            }
+          } else {
+            std::set<Value*> Duplicates;
+            for (unsigned i = 0, e = Factors.size(); i != e; ++i) {
+              if (Duplicates.insert(Factors[i]).second) {
+                unsigned Occ = ++FactorOccurrences[Factors[i]];
+                if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[i]; }
               }
-            } else {
-              std::set<Value*> Duplicates;
-              for (unsigned i = 0, e = Factors.size(); i != e; ++i)
-                if (Duplicates.insert(Factors[i]).second) {
-                  unsigned Occ = ++FactorOccurrences[Factors[i]];
-                  if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factors[i]; }
-                }
             }
           }
+        }
       }
     }
 
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 60a127a..e307ea7 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -519,7 +519,7 @@
         return 0;
       
     } else if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
-      // Storing the pointer, not the into the value?
+      // Storing the pointer, not into the value?
       if (SI->getOperand(0) == V) return 0;
       
       // NOTE: We could handle storing of FP imms into integers here!
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 1a650cc..243365e 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -378,10 +378,9 @@
 /// specify the full Instruction::OPCODE identifier.
 ///
 Constant *ConstantExpr::getNeg(Constant *C) {
-  if (!C->getType()->isFloatingPoint())
-    return get(Instruction::Sub, getNullValue(C->getType()), C);
-  else
-    return get(Instruction::Sub, ConstantFP::get(C->getType(), -0.0), C);
+  return get(Instruction::Sub,
+             ConstantExpr::getZeroValueForNegationExpr(C->getType()),
+             C);
 }
 Constant *ConstantExpr::getNot(Constant *C) {
   assert(isa<ConstantInt>(C) && "Cannot NOT a nonintegral type!");
@@ -1882,6 +1881,20 @@
   return getShuffleVectorTy(V1->getType(), V1, V2, Mask);
 }
 
+Constant *ConstantExpr::getZeroValueForNegationExpr(const Type *Ty) {
+  if ((const PackedType *PTy = dyn_cast<PackedType>(Ty)) &&
+      PTy->getElementType()->isFloatingPoint()) {
+    std::vector<Constant*> zeros(PTy->getNumElements(),
+                                 ConstantFP::get(PTy->getElementType(), -0.0));
+    return ConstantPacked::get(PTy, zeros);
+  }
+
+  if (Ty->isFloatingPoint())
+    return ConstantFP::get(Ty, -0.0);
+
+  return Constant::getNullValue(Ty);
+}
+
 // destroyConstant - Remove the constant from the constant table...
 //
 void ConstantExpr::destroyConstant() {
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index f98f7cb..0d40ee7 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1092,26 +1092,18 @@
 
 BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
-  if (!Op->getType()->isFloatingPoint())
-    return new BinaryOperator(Instruction::Sub,
-                              Constant::getNullValue(Op->getType()), Op,
-                              Op->getType(), Name, InsertBefore);
-  else
-    return new BinaryOperator(Instruction::Sub,
-                              ConstantFP::get(Op->getType(), -0.0), Op,
-                              Op->getType(), Name, InsertBefore);
+  Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
+  return new BinaryOperator(Instruction::Sub,
+                            zero, Op,
+                            Op->getType(), Name, InsertBefore);
 }
 
 BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
                                           BasicBlock *InsertAtEnd) {
-  if (!Op->getType()->isFloatingPoint())
-    return new BinaryOperator(Instruction::Sub,
-                              Constant::getNullValue(Op->getType()), Op,
-                              Op->getType(), Name, InsertAtEnd);
-  else
-    return new BinaryOperator(Instruction::Sub,
-                              ConstantFP::get(Op->getType(), -0.0), Op,
-                              Op->getType(), Name, InsertAtEnd);
+  Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
+  return new BinaryOperator(Instruction::Sub,
+                            zero, Op,
+                            Op->getType(), Name, InsertAtEnd);
 }
 
 BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
@@ -1153,10 +1145,8 @@
 bool BinaryOperator::isNeg(const Value *V) {
   if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
     if (Bop->getOpcode() == Instruction::Sub)
-      if (!V->getType()->isFloatingPoint())
-        return Bop->getOperand(0) == Constant::getNullValue(Bop->getType());
-      else
-        return Bop->getOperand(0) == ConstantFP::get(Bop->getType(), -0.0);
+      return Bop->getOperand(0) ==
+             ConstantExpr::getZeroValueForNegationExpr(Bop->getType());
   return false;
 }
 
@@ -1913,9 +1903,7 @@
     assert(Op0Ty == Op1Ty &&
            "Both operands to ICmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) ||
-           (isa<PackedType>(Op0Ty) && 
-            cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
+    assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) &&
            "Invalid operand types for ICmp instruction");
     return;
   }
@@ -1927,8 +1915,7 @@
   assert(Op0Ty == Op1Ty &&
          "Both operands to FCmp instruction are not of the same type!");
   // Check that the operands are the right type
-  assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
-         cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint()) &&
+  assert(Op0Ty->isFloatingPoint() &&
          "Invalid operand types for FCmp instruction");
 }
   
@@ -1948,9 +1935,7 @@
     assert(Op0Ty == Op1Ty &&
           "Both operands to ICmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) ||
-           (isa<PackedType>(Op0Ty) && 
-            cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
+    assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) &&
            "Invalid operand types for ICmp instruction");
     return;
   }
@@ -1962,8 +1947,7 @@
   assert(Op0Ty == Op1Ty &&
           "Both operands to FCmp instruction are not of the same type!");
   // Check that the operands are the right type
-  assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
-         cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint()) &&
+  assert(Op0Ty->isFloatingPoint() &&
         "Invalid operand types for FCmp instruction");
 }