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

Chris Lattner lattner at cs.uiuc.edu
Thu Apr 13 22:10:32 PDT 2006



Changes in directory llvm/lib/Analysis:

ValueNumbering.cpp updated: 1.16 -> 1.17
---
Log message:

Implement value #'ing for vector operations, implementing
Regression/Transforms/GCSE/vectorops.ll


---
Diffs of the changes:  (+38 -32)

 ValueNumbering.cpp |   70 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 38 insertions(+), 32 deletions(-)


Index: llvm/lib/Analysis/ValueNumbering.cpp
diff -u llvm/lib/Analysis/ValueNumbering.cpp:1.16 llvm/lib/Analysis/ValueNumbering.cpp:1.17
--- llvm/lib/Analysis/ValueNumbering.cpp:1.16	Sat Feb  4 03:15:29 2006
+++ llvm/lib/Analysis/ValueNumbering.cpp	Fri Apr 14 00:10:20 2006
@@ -73,14 +73,18 @@
     std::vector<Value*> &RetVals;
     BVNImpl(std::vector<Value*> &RV) : RetVals(RV) {}
 
-    void handleBinaryInst(Instruction &I);
-    void visitBinaryOperator(BinaryOperator &I) {
-      handleBinaryInst((Instruction&)I);
-    }
-    void visitGetElementPtrInst(GetElementPtrInst &I);
     void visitCastInst(CastInst &I);
-    void visitShiftInst(ShiftInst &I) { handleBinaryInst((Instruction&)I); }
-    void visitSelectInst(SelectInst &I);
+    void visitGetElementPtrInst(GetElementPtrInst &I);
+
+    void handleBinaryInst(Instruction &I);
+    void visitBinaryOperator(Instruction &I)     { handleBinaryInst(I); }
+    void visitShiftInst(Instruction &I)          { handleBinaryInst(I); }
+    void visitExtractElementInst(Instruction &I) { handleBinaryInst(I); }
+
+    void handleTernaryInst(Instruction &I);
+    void visitSelectInst(Instruction &I)         { handleTernaryInst(I); }
+    void visitInsertElementInst(Instruction &I)  { handleTernaryInst(I); }
+    void visitShuffleVectorInst(Instruction &I)  { handleTernaryInst(I); }
     void visitInstruction(Instruction &) {
       // Cannot value number calls or terminator instructions.
     }
@@ -148,6 +152,24 @@
   return false;
 }
 
+// isIdenticalTernaryInst - Return true if the two ternary instructions are
+// identical.
+//
+static inline bool isIdenticalTernaryInst(const Instruction &I1,
+                                          const Instruction *I2) {
+  // Is it embedded in the same function?  (This could be false if LHS
+  // is a constant or global!)
+  if (I1.getParent()->getParent() != I2->getParent()->getParent())
+    return false;
+  
+  // They are identical if all operands are the same!
+  return I1.getOperand(0) == I2->getOperand(0) &&
+         I1.getOperand(1) == I2->getOperand(1) &&
+         I1.getOperand(2) == I2->getOperand(2);
+}
+
+
+
 void BVNImpl::handleBinaryInst(Instruction &I) {
   Value *LHS = I.getOperand(0);
 
@@ -199,37 +221,21 @@
       }
 }
 
-// isIdenticalSelectInst - Return true if the two select instructions are
-// identical.
-//
-static inline bool isIdenticalSelectInst(const SelectInst &I1,
-                                         const SelectInst *I2) {
-  // Is it embedded in the same function?  (This could be false if LHS
-  // is a constant or global!)
-  if (I1.getParent()->getParent() != I2->getParent()->getParent())
-    return false;
+void BVNImpl::handleTernaryInst(Instruction &I) {
+  Value *Op0 = I.getOperand(0);
+  Instruction *OtherInst;
   
-  // They are identical if both operands are the same!
-  return I1.getOperand(0) == I2->getOperand(0) &&
-         I1.getOperand(1) == I2->getOperand(1) &&
-         I1.getOperand(2) == I2->getOperand(2);
-    return true;
-  
-  return false;
-}
-
-void BVNImpl::visitSelectInst(SelectInst &I) {
-  Value *Cond = I.getOperand(0);
-  
-  for (Value::use_iterator UI = Cond->use_begin(), UE = Cond->use_end();
+  for (Value::use_iterator UI = Op0->use_begin(), UE = Op0->use_end();
        UI != UE; ++UI)
-    if (SelectInst *Other = dyn_cast<SelectInst>(*UI))
+    if ((OtherInst = dyn_cast<Instruction>(*UI)) && 
+        OtherInst->getOpcode() == I.getOpcode()) {
       // Check to see if this new select is not I, but has the same operands.
-      if (Other != &I && isIdenticalSelectInst(I, Other)) {
+      if (OtherInst != &I && isIdenticalTernaryInst(I, OtherInst)) {
         // These instructions are identical.  Handle the situation.
-        RetVals.push_back(Other);
+        RetVals.push_back(OtherInst);
       }
         
+    }
 }
 
 






More information about the llvm-commits mailing list