summaryrefslogtreecommitdiffstats
path: root/lib/Analysis/ValueNumbering.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-20 01:22:35 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-20 01:22:35 +0000
commit45fb3f3cb2b8efc01d9bbe42a64194f35b92c759 (patch)
treeeee41137decfef068a9e77761597739a216eb557 /lib/Analysis/ValueNumbering.cpp
parent36699cabc5ab461f53047be6384a27fb9a7845ce (diff)
downloadexternal_llvm-45fb3f3cb2b8efc01d9bbe42a64194f35b92c759.zip
external_llvm-45fb3f3cb2b8efc01d9bbe42a64194f35b92c759.tar.gz
external_llvm-45fb3f3cb2b8efc01d9bbe42a64194f35b92c759.tar.bz2
For 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31867 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueNumbering.cpp')
-rw-r--r--lib/Analysis/ValueNumbering.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Analysis/ValueNumbering.cpp b/lib/Analysis/ValueNumbering.cpp
index 0224a01..03b9f6b 100644
--- a/lib/Analysis/ValueNumbering.cpp
+++ b/lib/Analysis/ValueNumbering.cpp
@@ -75,6 +75,7 @@ namespace {
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::visitCastInst(CastInst &CI) {
}
}
+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.