[llvm-commits] CVS: llvm/lib/Analysis/ValueNumbering.cpp

Reid Spencer reid at x10sys.com
Sun Nov 19 17:22:56 PST 2006



Changes in directory llvm/lib/Analysis:

ValueNumbering.cpp updated: 1.21 -> 1.22
---
Log message:

For PR950: http://llvm.org/PR950 :
First in a series of patches to convert SetCondInst into ICmpInst and 
FCmpInst using only two opcodes and having the instructions contain their
predicate value. Nothing uses these classes yet. More patches to follow.


---
Diffs of the changes:  (+23 -0)

 ValueNumbering.cpp |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+)


Index: llvm/lib/Analysis/ValueNumbering.cpp
diff -u llvm/lib/Analysis/ValueNumbering.cpp:1.21 llvm/lib/Analysis/ValueNumbering.cpp:1.22
--- llvm/lib/Analysis/ValueNumbering.cpp:1.21	Sun Aug 27 19:42:29 2006
+++ llvm/lib/Analysis/ValueNumbering.cpp	Sun Nov 19 19:22:35 2006
@@ -75,6 +75,7 @@
 
     void visitCastInst(CastInst &I);
     void visitGetElementPtrInst(GetElementPtrInst &I);
+    void visitCmpInst(CmpInst &I);
 
     void handleBinaryInst(Instruction &I);
     void visitBinaryOperator(Instruction &I)     { handleBinaryInst(I); }
@@ -124,6 +125,28 @@
       }
 }
 
+void  BVNImpl::visitCmpInst(CmpInst &CI1) {
+  Value *LHS = CI1.getOperand(0);
+  for (Value::use_iterator UI = LHS->use_begin(), UE = LHS->use_end();
+       UI != UE; ++UI)
+    if (CmpInst *CI2 = dyn_cast<CmpInst>(*UI))
+      // Check to see if this compare instruction is not CI, but same opcode,
+      // same predicate, and in the same function.
+      if (CI2 != &CI1 && CI2->getOpcode() == CI1.getOpcode() &&
+          CI2->getPredicate() == CI1.getPredicate() &&
+          CI2->getParent()->getParent() == CI1.getParent()->getParent())
+        // If the operands are the same
+        if ((CI2->getOperand(0) == CI1.getOperand(0) &&
+            CI2->getOperand(1) == CI1.getOperand(1)) ||
+            // Or the compare is commutative and the operands are reversed 
+            (CI1.isCommutative() && 
+             CI2->getOperand(0) == CI1.getOperand(1) &&
+             CI2->getOperand(1) == CI1.getOperand(0)))
+          // Then the instructiosn are identical, add to list.
+          RetVals.push_back(CI2);
+}
+
+
 
 // isIdenticalBinaryInst - Return true if the two binary instructions are
 // identical.






More information about the llvm-commits mailing list