[llvm-commits] [llvm] r92700 - /llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Mon Jan 4 23:04:23 PST 2010


Author: lattner
Date: Tue Jan  5 01:04:23 2010
New Revision: 92700

URL: http://llvm.org/viewvc/llvm-project?rev=92700&view=rev
Log:
all the places we use hasOneUse() we know are instructions, so inline
and simplify.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

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

==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue Jan  5 01:04:23 2010
@@ -77,14 +77,8 @@
 }
 
 
-// isOnlyUse - Return true if this instruction will be deleted if we stop using
-// it.
-static bool isOnlyUse(Value *V) {
-  return V->hasOneUse() || isa<Constant>(V);
-}
-
 // getPromotedType - Return the specified type promoted as it would be to pass
-// though a va_arg area...
+// though a va_arg area.
 static const Type *getPromotedType(const Type *Ty) {
   if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) {
     if (ITy->getBitWidth() < 32)
@@ -152,6 +146,7 @@
     Changed = !I.swapOperands();
 
   if (!I.isAssociative()) return Changed;
+  
   Instruction::BinaryOps Opcode = I.getOpcode();
   if (BinaryOperator *Op = dyn_cast<BinaryOperator>(I.getOperand(0)))
     if (Op->getOpcode() == Opcode && isa<Constant>(Op->getOperand(1))) {
@@ -162,9 +157,11 @@
         I.setOperand(0, Op->getOperand(0));
         I.setOperand(1, Folded);
         return true;
-      } else if (BinaryOperator *Op1=dyn_cast<BinaryOperator>(I.getOperand(1)))
+      }
+      
+      if (BinaryOperator *Op1 = dyn_cast<BinaryOperator>(I.getOperand(1)))
         if (Op1->getOpcode() == Opcode && isa<Constant>(Op1->getOperand(1)) &&
-            isOnlyUse(Op) && isOnlyUse(Op1)) {
+            Op->hasOneUse() && Op1->hasOneUse()) {
           Constant *C1 = cast<Constant>(Op->getOperand(1));
           Constant *C2 = cast<Constant>(Op1->getOperand(1));
 
@@ -2555,7 +2552,7 @@
     ConstantInt *C1 = 0; Value *X = 0;
     // (X & C1) | C2 --> (X | C2) & (C1|C2)
     if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) &&
-        isOnlyUse(Op0)) {
+        Op0->hasOneUse()) {
       Value *Or = Builder->CreateOr(X, RHS);
       Or->takeName(Op0);
       return BinaryOperator::CreateAnd(Or, 
@@ -2565,7 +2562,7 @@
 
     // (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
     if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1))) &&
-        isOnlyUse(Op0)) {
+        Op0->hasOneUse()) {
       Value *Or = Builder->CreateOr(X, RHS);
       Or->takeName(Op0);
       return BinaryOperator::CreateXor(Or,
@@ -2665,7 +2662,7 @@
     
     // Check to see if we have any common things being and'ed.  If so, find the
     // terms for V1 & (V2|V3).
-    if (isOnlyUse(Op0) || isOnlyUse(Op1)) {
+    if (Op0->hasOneUse() || Op1->hasOneUse()) {
       V1 = 0;
       if (A == B)      // (A & C)|(A & D) == A & (C|D)
         V1 = A, V2 = C, V3 = D;





More information about the llvm-commits mailing list