[llvm-commits] [llvm] r75528 - in /llvm/trunk: include/llvm/Constant.h include/llvm/Constants.h include/llvm/InstrTypes.h lib/Target/CBackend/CBackend.cpp lib/Transforms/Scalar/InstructionCombining.cpp lib/Transforms/Scalar/Reassociate.cpp lib/VMCore/Instructions.cpp

Owen Anderson resistor at mac.com
Mon Jul 13 15:18:28 PDT 2009


Author: resistor
Date: Mon Jul 13 17:18:28 2009
New Revision: 75528

URL: http://llvm.org/viewvc/llvm-project?rev=75528&view=rev
Log:
These don't really need contexts either.

Modified:
    llvm/trunk/include/llvm/Constant.h
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/include/llvm/InstrTypes.h
    llvm/trunk/lib/Target/CBackend/CBackend.cpp
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constant.h?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constant.h (original)
+++ llvm/trunk/include/llvm/Constant.h Mon Jul 13 17:18:28 2009
@@ -64,6 +64,10 @@
   /// getNullValue.
   virtual bool isNullValue() const = 0;
 
+  /// isNegativeZeroValue - Return true if the value is what would be returned 
+  /// by getZeroValueForNegation.
+  virtual bool isNegativeZeroValue() const { return isNullValue(); }
+
   /// canTrap - Return true if evaluation of this constant could trap.  This is
   /// true for things like constant expressions that could divide by zero.
   bool canTrap() const;

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Mon Jul 13 17:18:28 2009
@@ -270,6 +270,12 @@
   /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
   /// considers -0.0 to be null as well as 0.0.  :(
   virtual bool isNullValue() const;
+  
+  /// isNegativeZeroValue - Return true if the value is what would be returned 
+  /// by getZeroValueForNegation.
+  virtual bool isNegativeZeroValue() const {
+    return Val.isZero() && Val.isNegative();
+  }
 
   /// isExactlyValue - We don't rely on operator== working on double values, as
   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.

Modified: llvm/trunk/include/llvm/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InstrTypes.h?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/include/llvm/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/InstrTypes.h Mon Jul 13 17:18:28 2009
@@ -224,8 +224,8 @@
   /// isNeg, isFNeg, isNot - Check if the given Value is a
   /// NEG, FNeg, or NOT instruction.
   ///
-  static bool isNeg(LLVMContext &Context, const Value *V);
-  static bool isFNeg(LLVMContext &Context, const Value *V);
+  static bool isNeg(const Value *V);
+  static bool isFNeg(const Value *V);
   static bool isNot(const Value *V);
 
   /// getNegArgument, getNotArgument - Helper functions to extract the

Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Mon Jul 13 17:18:28 2009
@@ -2621,11 +2621,11 @@
 
   // If this is a negation operation, print it out as such.  For FP, we don't
   // want to print "-0.0 - X".
-  if (BinaryOperator::isNeg(*Context, &I)) {
+  if (BinaryOperator::isNeg(&I)) {
     Out << "-(";
     writeOperand(BinaryOperator::getNegArgument(cast<BinaryOperator>(&I)));
     Out << ")";
-  } else if (BinaryOperator::isFNeg(*Context, &I)) {
+  } else if (BinaryOperator::isFNeg(&I)) {
     Out << "-(";
     writeOperand(BinaryOperator::getFNegArgument(cast<BinaryOperator>(&I)));
     Out << ")";

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jul 13 17:18:28 2009
@@ -410,8 +410,8 @@
 //   0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
 static unsigned getComplexity(LLVMContext *Context, Value *V) {
   if (isa<Instruction>(V)) {
-    if (BinaryOperator::isNeg(*Context, V) ||
-        BinaryOperator::isFNeg(*Context, V) ||
+    if (BinaryOperator::isNeg(V) ||
+        BinaryOperator::isFNeg(V) ||
         BinaryOperator::isNot(V))
       return 3;
     return 4;
@@ -573,7 +573,7 @@
 // if the LHS is a constant zero (which is the 'negate' form).
 //
 static inline Value *dyn_castNegVal(Value *V, LLVMContext *Context) {
-  if (BinaryOperator::isNeg(*Context, V))
+  if (BinaryOperator::isNeg(V))
     return BinaryOperator::getNegArgument(V);
 
   // Constants can be considered to be negated values if they can be folded.
@@ -592,7 +592,7 @@
 // form).
 //
 static inline Value *dyn_castFNegVal(Value *V, LLVMContext *Context) {
-  if (BinaryOperator::isFNeg(*Context, V))
+  if (BinaryOperator::isFNeg(V))
     return BinaryOperator::getFNegArgument(V);
 
   // Constants can be considered to be negated values if they can be folded.

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Mon Jul 13 17:18:28 2009
@@ -178,7 +178,7 @@
   // If this is a not or neg instruction, do not count it for rank.  This
   // assures us that X and ~X will have the same rank.
   if (!I->getType()->isInteger() ||
-      (!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(*Context, I)))
+      (!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(I)))
     ++Rank;
 
   //DOUT << "Calculated Rank[" << V->getName() << "] = "
@@ -264,12 +264,12 @@
   // If this is a multiply expression tree and it contains internal negations,
   // transform them into multiplies by -1 so they can be reassociated.
   if (I->getOpcode() == Instruction::Mul) {
-    if (!LHSBO && LHS->hasOneUse() && BinaryOperator::isNeg(*Context, LHS)) {
+    if (!LHSBO && LHS->hasOneUse() && BinaryOperator::isNeg(LHS)) {
       LHS = LowerNegateToMultiply(cast<Instruction>(LHS),
                                   ValueRankMap, Context);
       LHSBO = isReassociableOp(LHS, Opcode);
     }
-    if (!RHSBO && RHS->hasOneUse() && BinaryOperator::isNeg(*Context, RHS)) {
+    if (!RHSBO && RHS->hasOneUse() && BinaryOperator::isNeg(RHS)) {
       RHS = LowerNegateToMultiply(cast<Instruction>(RHS),
                                   ValueRankMap, Context);
       RHSBO = isReassociableOp(RHS, Opcode);
@@ -409,7 +409,7 @@
 /// X-Y into (X + -Y).
 static bool ShouldBreakUpSubtract(LLVMContext *Context, Instruction *Sub) {
   // If this is a negation, we can't split it up!
-  if (BinaryOperator::isNeg(*Context, Sub))
+  if (BinaryOperator::isNeg(Sub))
     return false;
   
   // Don't bother to break this up unless either the LHS is an associable add or
@@ -663,7 +663,7 @@
     for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
       assert(i < Ops.size());
       // Check for X and -X in the operand list.
-      if (BinaryOperator::isNeg(*Context, Ops[i].Op)) {
+      if (BinaryOperator::isNeg(Ops[i].Op)) {
         Value *X = BinaryOperator::getNegArgument(Ops[i].Op);
         unsigned FoundX = FindInOperandList(Ops, i, X);
         if (FoundX != i) {
@@ -801,7 +801,7 @@
       if (ShouldBreakUpSubtract(Context, BI)) {
         BI = BreakUpSubtract(Context, BI, ValueRankMap);
         MadeChange = true;
-      } else if (BinaryOperator::isNeg(*Context, BI)) {
+      } else if (BinaryOperator::isNeg(BI)) {
         // Otherwise, this is a negation.  See if the operand is a multiply tree
         // and if this is not an inner node of a multiply tree.
         if (isReassociableOp(BI->getOperand(1), Instruction::Mul) &&

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=75528&r1=75527&r2=75528&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Mon Jul 13 17:18:28 2009
@@ -1711,19 +1711,19 @@
   return false;
 }
 
-bool BinaryOperator::isNeg(LLVMContext &Context, const Value *V) {
+bool BinaryOperator::isNeg(const Value *V) {
   if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
     if (Bop->getOpcode() == Instruction::Sub)
-      return Bop->getOperand(0) ==
-             Context.getZeroValueForNegation(Bop->getType());
+      if (Constant* C = dyn_cast<Constant>(Bop->getOperand(0)))
+        return C->isNegativeZeroValue();
   return false;
 }
 
-bool BinaryOperator::isFNeg(LLVMContext &Context, const Value *V) {
+bool BinaryOperator::isFNeg(const Value *V) {
   if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
     if (Bop->getOpcode() == Instruction::FSub)
-      return Bop->getOperand(0) ==
-             Context.getZeroValueForNegation(Bop->getType());
+      if (Constant* C = dyn_cast<Constant>(Bop->getOperand(0)))
+      return C->isNegativeZeroValue();
   return false;
 }
 





More information about the llvm-commits mailing list