From 24d6da5fedcf39891f7d8c5b031c01324b3db545 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 21 Jan 2007 00:29:26 +0000 Subject: [PATCH] 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 --- docs/LangRef.html | 5 +- .../llvm/Analysis/ScalarEvolutionExpander.h | 3 +- include/llvm/Constants.h | 7 +- include/llvm/Support/PatternMatch.h | 31 ------ lib/Analysis/ScalarEvolutionExpander.cpp | 3 +- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 94 ++++++++++--------- lib/ExecutionEngine/Interpreter/Execution.cpp | 2 +- lib/Transforms/ExprTypeConvert.cpp | 4 +- lib/Transforms/IPO/GlobalOpt.cpp | 1 + lib/Transforms/Scalar/Reassociate.cpp | 52 +++++----- .../Scalar/ScalarReplAggregates.cpp | 2 +- lib/VMCore/Constants.cpp | 21 ++++- lib/VMCore/Instructions.cpp | 44 +++------ 13 files changed, 119 insertions(+), 150 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index c423c0b5745..4b71ba30a46 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -2867,7 +2867,7 @@ used to make a no-op cast because it always changes bits. Use
- 'fptoui .. to' Instruction + 'fptoui .. to' Instruction
@@ -3270,9 +3270,6 @@ yields a i1 result, as follows:
  • uno: yields true if either operand is a QNAN.
  • true: always yields true, regardless of operands.
  • -

    If the operands are packed typed, the elements of -the vector are compared in turn and the predicate must hold for all elements. -

    Example:
      <result> = fcmp oeq float 4.0, 5.0    ; yields: result=false
    diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h
    index 80e0a9d8cf1..fad2da9b9b6 100644
    --- a/include/llvm/Analysis/ScalarEvolutionExpander.h
    +++ b/include/llvm/Analysis/ScalarEvolutionExpander.h
    @@ -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);
    diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
    index 5a17f398870..c92229e8793 100644
    --- a/include/llvm/Constants.h
    +++ b/include/llvm/Constants.h
    @@ -36,7 +36,7 @@ template
     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; }
    diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
    index f0acbcbaa6e..97e9b5f961c 100644
    --- a/include/llvm/Support/PatternMatch.h
    +++ b/include/llvm/Support/PatternMatch.h
    @@ -305,37 +305,6 @@ m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
     // Matchers for unary operators
     //
     
    -template
    -struct neg_match {
    -  LHS_t L;
    -
    -  neg_match(const LHS_t &LHS) : L(LHS) {}
    -
    -  template
    -  bool match(OpTy *V) {
    -    if (Instruction *I = dyn_cast(V))
    -      if (I->getOpcode() == Instruction::Sub)
    -        return matchIfNeg(I->getOperand(0), I->getOperand(1));
    -    if (ConstantExpr *CE = dyn_cast(V))
    -      if (CE->getOpcode() == Instruction::Sub)
    -        return matchIfNeg(CE->getOperand(0), CE->getOperand(1));
    -    if (ConstantInt *CI = dyn_cast(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
    -inline neg_match m_Neg(const LHS &L) { return L; }
    -
    -
     template
     struct not_match {
       LHS_t L;
    diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
    index e9e7e794ce7..3d985ab8852 100644
    --- a/lib/Analysis/ScalarEvolutionExpander.cpp
    +++ b/lib/Analysis/ScalarEvolutionExpander.cpp
    @@ -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());
     
    diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    index e8d58453c24..bf163270b54 100644
    --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    @@ -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(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(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(Ty)) {
    +    visitVectorBinary(I, ISD::VSUB);
    +  } else if (Ty->isFloatingPoint()) {
         if (ConstantFP *CFP = dyn_cast(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(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(I.getType()));
    +  const PackedType *Ty = cast(I.getType());
    +  SDOperand Typ = DAG.getValueType(TLI.getValueType(Ty->getElementType()));
     
    -  if (const PackedType *PTy = dyn_cast(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(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 41d7aad8265..2ddfc97c1b4 100644
    --- a/lib/ExecutionEngine/Interpreter/Execution.cpp
    +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
    @@ -1498,7 +1498,7 @@ GenericValue Interpreter::executeSIToFPInst(Value *SrcVal, const Type *DstTy,
       const IntegerType *SITy = cast(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 1ed804e23de..ee5549bad2d 100644
    --- a/lib/Transforms/ExprTypeConvert.cpp
    +++ b/lib/Transforms/ExprTypeConvert.cpp
    @@ -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;
    diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
    index bbf5241b34f..d9ba12c7845 100644
    --- a/lib/Transforms/IPO/GlobalOpt.cpp
    +++ b/lib/Transforms/IPO/GlobalOpt.cpp
    @@ -1343,6 +1343,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
           if (Constant *SOVConstant = dyn_cast(GS.StoredOnceValue))
             if (GV->getType()->getElementType() != Type::Int1Ty &&
                 !GV->getType()->getElementType()->isFloatingPoint() &&
    +            !isa(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 287bff2a2f1..4fcbf35f567 100644
    --- a/lib/Transforms/Scalar/Reassociate.cpp
    +++ b/lib/Transforms/Scalar/Reassociate.cpp
    @@ -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 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(Ops[i].Op))
    -          if (BOp->getOpcode() == Instruction::Mul && BOp->use_empty()) {
    -            // Compute all of the factors of this added value.
    -            std::vector 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(Ops[i].Op)) {
    +        if (BOp->getOpcode() == Instruction::Mul && BOp->use_empty()) {
    +          // Compute all of the factors of this added value.
    +          std::vector 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 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 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 60a127a9219..e307ea70086 100644
    --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
    +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
    @@ -519,7 +519,7 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) {
             return 0;
           
         } else if (StoreInst *SI = dyn_cast(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 1a650cc5e1c..243365e9c66 100644
    --- a/lib/VMCore/Constants.cpp
    +++ b/lib/VMCore/Constants.cpp
    @@ -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(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(Ty)) &&
    +      PTy->getElementType()->isFloatingPoint()) {
    +    std::vector 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 f98f7cb85a8..0d40ee7cf96 100644
    --- a/lib/VMCore/Instructions.cpp
    +++ b/lib/VMCore/Instructions.cpp
    @@ -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(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(Op0Ty) ||
    -           (isa(Op0Ty) && 
    -            cast(Op0Ty)->getElementType()->isInteger()) &&
    +    assert((Op0Ty->isInteger() || isa(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(Op0Ty) &&
    -         cast(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(Op0Ty) ||
    -           (isa(Op0Ty) && 
    -            cast(Op0Ty)->getElementType()->isInteger()) &&
    +    assert(Op0Ty->isInteger() || isa(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(Op0Ty) &&
    -         cast(Op0Ty)->getElementType()->isFloatingPoint()) &&
    +  assert(Op0Ty->isFloatingPoint() &&
             "Invalid operand types for FCmp instruction");
     }