[llvm-commits] [llvm] r51024 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Owen Anderson
resistor at mac.com
Tue May 13 01:17:23 PDT 2008
Author: resistor
Date: Tue May 13 03:17:22 2008
New Revision: 51024
URL: http://llvm.org/viewvc/llvm-project?rev=51024&view=rev
Log:
Add support for non-local CSE of read-only calls.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=51024&r1=51023&r2=51024&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue May 13 03:17:22 2008
@@ -56,8 +56,8 @@
FCMPULT, FCMPULE, FCMPUNE, EXTRACT, INSERT,
SHUFFLE, SELECT, TRUNC, ZEXT, SEXT, FPTOUI,
FPTOSI, UITOFP, SITOFP, FPTRUNC, FPEXT,
- PTRTOINT, INTTOPTR, BITCAST, GEP, CALL, EMPTY,
- TOMBSTONE };
+ PTRTOINT, INTTOPTR, BITCAST, GEP, CALL, CONSTANT,
+ EMPTY, TOMBSTONE };
ExpressionOpcode opcode;
const Type* type;
@@ -147,6 +147,7 @@
Expression create_expression(CastInst* C);
Expression create_expression(GetElementPtrInst* G);
Expression create_expression(CallInst* C);
+ Expression create_expression(Constant* C);
public:
ValueTable() : nextValueNumber(1) { }
uint32_t lookup_or_add(Value* V);
@@ -391,7 +392,7 @@
Expression ValueTable::create_expression(GetElementPtrInst* G) {
Expression e;
-
+
e.firstVN = lookup_or_add(G->getPointerOperand());
e.secondVN = 0;
e.thirdVN = 0;
@@ -434,26 +435,58 @@
} else if (AA->onlyReadsMemory(C)) {
Expression e = create_expression(C);
- Instruction* dep = MD->getDependency(C);
-
- if (dep == MemoryDependenceAnalysis::NonLocal ||
- !isa<CallInst>(dep)) {
+ if (expressionNumbering.find(e) == expressionNumbering.end()) {
expressionNumbering.insert(std::make_pair(e, nextValueNumber));
valueNumbering.insert(std::make_pair(V, nextValueNumber));
+ return nextValueNumber++;
+ }
+
+ DenseMap<BasicBlock*, Value*> deps;
+ MD->getNonLocalDependency(C, deps);
+ Value* dep = 0;
+
+ for (DenseMap<BasicBlock*, Value*>::iterator I = deps.begin(),
+ E = deps.end(); I != E; ++I) {
+ if (I->second == MemoryDependenceAnalysis::None) {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ } else if (I->second != MemoryDependenceAnalysis::NonLocal) {
+ if (DT->dominates(I->first, C->getParent())) {
+ dep = I->second;
+ } else {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ }
+ }
+ }
+ if (!dep || !isa<CallInst>(dep)) {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
}
CallInst* cdep = cast<CallInst>(dep);
- Expression d_exp = create_expression(cdep);
- if (e != d_exp) {
- expressionNumbering.insert(std::make_pair(e, nextValueNumber));
+ if (cdep->getCalledFunction() != C->getCalledFunction() ||
+ cdep->getNumOperands() != C->getNumOperands()) {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+ return nextValueNumber++;
+ } else if (!C->getCalledFunction()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
-
return nextValueNumber++;
} else {
- uint32_t v = expressionNumbering[d_exp];
+ for (unsigned i = 1; i < C->getNumOperands(); ++i) {
+ uint32_t c_vn = lookup_or_add(C->getOperand(i));
+ uint32_t cd_vn = lookup_or_add(cdep->getOperand(i));
+ if (c_vn != cd_vn) {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+ return nextValueNumber++;
+ }
+ }
+
+ uint32_t v = valueNumbering[cdep];
valueNumbering.insert(std::make_pair(V, v));
return v;
}
More information about the llvm-commits
mailing list