summaryrefslogtreecommitdiff
path: root/lib/Analysis/ValueNumbering.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-04 09:15:29 +0000
committerChris Lattner <sabre@nondot.org>2006-02-04 09:15:29 +0000
commit03f774ad8087a111781ec491169d5c2305e486b7 (patch)
tree8e801f748190172ca40a708026ca0cc56f49f6ef /lib/Analysis/ValueNumbering.cpp
parent9c4815a0362575bcd207619188156b5fad73c2bc (diff)
downloadllvm-03f774ad8087a111781ec491169d5c2305e486b7.tar.gz
llvm-03f774ad8087a111781ec491169d5c2305e486b7.tar.bz2
llvm-03f774ad8087a111781ec491169d5c2305e486b7.tar.xz
Value# select instructions, allowing -gcse to remove duplicates
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueNumbering.cpp')
-rw-r--r--lib/Analysis/ValueNumbering.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/Analysis/ValueNumbering.cpp b/lib/Analysis/ValueNumbering.cpp
index 0ca280106b..0050e06091 100644
--- a/lib/Analysis/ValueNumbering.cpp
+++ b/lib/Analysis/ValueNumbering.cpp
@@ -80,8 +80,9 @@ namespace {
void visitGetElementPtrInst(GetElementPtrInst &I);
void visitCastInst(CastInst &I);
void visitShiftInst(ShiftInst &I) { handleBinaryInst((Instruction&)I); }
+ void visitSelectInst(SelectInst &I);
void visitInstruction(Instruction &) {
- // Cannot value number calls or terminator instructions...
+ // Cannot value number calls or terminator instructions.
}
};
}
@@ -198,4 +199,38 @@ void BVNImpl::visitGetElementPtrInst(GetElementPtrInst &I) {
}
}
+// 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;
+
+ // 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();
+ UI != UE; ++UI)
+ if (SelectInst *Other = dyn_cast<SelectInst>(*UI))
+ // Check to see if this new select is not I, but has the same operands.
+ if (Other != &I && isIdenticalSelectInst(I, Other)) {
+ // These instructions are identical. Handle the situation.
+ RetVals.push_back(Other);
+ }
+
+}
+
+
void llvm::BasicValueNumberingStub() { }