For PR970:
authorReid Spencer <rspencer@reidspencer.com>
Sun, 21 Jan 2007 00:29:26 +0000 (00:29 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sun, 21 Jan 2007 00:29:26 +0000 (00:29 +0000)
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

13 files changed:
docs/LangRef.html
include/llvm/Analysis/ScalarEvolutionExpander.h
include/llvm/Constants.h
include/llvm/Support/PatternMatch.h
lib/Analysis/ScalarEvolutionExpander.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/Transforms/ExprTypeConvert.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Instructions.cpp

index c423c0b5745d29685fce1f2d0a6a9b1f440f4a97..4b71ba30a46ca99df074b55eaec68e7ab6892ab3 100644 (file)
@@ -2867,7 +2867,7 @@ used to make a <i>no-op cast</i> because it always changes bits. Use
 
 <!-- _______________________________________________________________________ -->
 <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 @@ yields a <a href="#t_primitive">i1</a> result, as follows:
   <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>
index 80e0a9d8cf1d9b77629100ccd25611ce9ef9ec8a..fad2da9b9b6ab0f562aefc4e45c1a846218d9d68 100644 (file)
@@ -60,8 +60,7 @@ namespace llvm {
     /// 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);
index 5a17f39887077e26068d172d42326d96eeb2979c..c92229e87937cf5c86b4fc5fa1626305a8513a17 100644 (file)
@@ -36,7 +36,7 @@ template<class ConstantClass, class TypeClass>
 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 @@ public:
   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; }
index f0acbcbaa6e009cbd7f53c03e53e29bc64a51f0b..97e9b5f961c4e98d7a5f143009ebd5ca9137b624 100644 (file)
@@ -305,37 +305,6 @@ m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
 // Matchers for unary operators
 //
 
-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;
index e9e7e794ce7d6863b9ed4ac87b2e4a998127a048..3d985ab88525bd4e3c1fb7b059c38a9ef5db046c 100644 (file)
@@ -123,8 +123,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
 
     // 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());
 
index e8d58453c240d8931b698541c7ce43b6919fc2f9..bf163270b5463007b39dc2e34a907e07fe6b64cb 100644 (file)
@@ -499,32 +499,37 @@ public:
   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::visitSwitch(SwitchInst &I) {
 
 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()));
+
+  setValue(&I, DAG.getNode(OpCode, MVT::Vector,
+                           getValue(I.getOperand(0)),
+                           getValue(I.getOperand(1)),
+                           DAG.getConstant(Ty->getNumElements(), MVT::i32),
+                           Typ));
+}
 
-  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));
-  }
+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) {
index 41d7aad826585b86ad6f500a6882293ade4a73ad..2ddfc97c1b406ffc418e78bd6e1d17eae0b75c52 100644 (file)
@@ -1498,7 +1498,7 @@ GenericValue Interpreter::executeSIToFPInst(Value *SrcVal, const Type *DstTy,
   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;
index 1ed804e23decef7eef24333d7c068d7688182211..ee5549bad2d2154ea4e359c7ec07d7d3295e37b7 100644 (file)
@@ -576,8 +576,8 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
       // 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;
index bbf5241b34f975612bc16c86322deff01a19c042..d9ba12c7845df9b4371fc53f685c5e358b009c67 100644 (file)
@@ -1343,6 +1343,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
       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);
index 287bff2a2f1f049c4500882ae700ea6bb80d43ba..4fcbf35f5675becf3883ec6a4ce5d0d93b6cdda9 100644 (file)
@@ -186,11 +186,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
 /// 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 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
     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]; }
-                }
             }
           }
+        }
       }
     }
 
index 60a127a9219b93081781ccba234328d53224963a..e307ea70086d05d84286660c3860d6dfdc5c1a52 100644 (file)
@@ -519,7 +519,7 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) {
         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!
index 1a650cc5e1cbd0e76625f57375c860f971e5afc5..243365e9c6618532a6a50c33d11576dca5b904d1 100644 (file)
@@ -378,10 +378,9 @@ bool ConstantExpr::isCompare() const {
 /// 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 @@ Constant *ConstantExpr::getShuffleVector(Constant *V1, Constant *V2,
   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() {
index f98f7cb85a8bca18e06428617e499cd2b616db78..0d40ee7cf96905c2423de584dfa4f7f8a96ce6dd 100644 (file)
@@ -1092,26 +1092,18 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
 
 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 @@ static inline bool isConstantAllOnes(const Value *V) {
 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 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
     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 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
   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 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
     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 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
   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");
 }