[llvm-commits] [llvm] r60309 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 30 15:39:23 PST 2008
Author: lattner
Date: Sun Nov 30 17:39:23 2008
New Revision: 60309
URL: http://llvm.org/viewvc/llvm-project?rev=60309&view=rev
Log:
improve indentation, do cheap checks before expensive ones,
remove some fixme's. This speeds up GVN very slightly on 403.gcc
(4.06->4.03s)
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=60309&r1=60308&r2=60309&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sun Nov 30 17:39:23 2008
@@ -461,8 +461,9 @@
if (local_dep.isNone()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
- } else if (Instruction *LocalDepInst = local_dep.getInst()) {
- // FIXME: INDENT PROPERLY!
+ }
+
+ if (Instruction *LocalDepInst = local_dep.getInst()) {
if (!isa<CallInst>(LocalDepInst)) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
@@ -470,28 +471,29 @@
CallInst* local_cdep = cast<CallInst>(LocalDepInst);
- // FIXME: INDENT PROPERLY.
if (local_cdep->getCalledFunction() != C->getCalledFunction() ||
local_cdep->getNumOperands() != C->getNumOperands()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
- } else if (!C->getCalledFunction()) {
+ }
+
+ if (!C->getCalledFunction()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
- } else {
- 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(local_cdep->getOperand(i));
- if (c_vn != cd_vn) {
- valueNumbering.insert(std::make_pair(V, nextValueNumber));
- return nextValueNumber++;
- }
- }
+ }
- uint32_t v = lookup_or_add(local_cdep);
- valueNumbering.insert(std::make_pair(V, v));
- return v;
+ 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(local_cdep->getOperand(i));
+ if (c_vn != cd_vn) {
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+ return nextValueNumber++;
+ }
}
+
+ uint32_t v = lookup_or_add(local_cdep);
+ valueNumbering.insert(std::make_pair(V, v));
+ return v;
}
@@ -499,27 +501,30 @@
MD->getNonLocalDependency(C, deps);
CallInst* cdep = 0;
+ // Check to see if we have a single dominating call instruction that is
+ // identical to C.
for (SmallVector<std::pair<BasicBlock*, MemDepResult>, 32>
::iterator I = deps.begin(), E = deps.end(); I != E; ++I) {
- if (I->second.isNone()) {
- valueNumbering.insert(std::make_pair(V, nextValueNumber));
-
- return nextValueNumber++;
- } else if (Instruction *NonLocalDepInst = I->second.getInst()) {
- // FIXME: INDENT PROPERLY
- // FIXME: All duplicated with non-local case.
- if (cdep == 0 && DT->properlyDominates(I->first, C->getParent())) {
- if (CallInst* CD = dyn_cast<CallInst>(NonLocalDepInst))
- cdep = CD;
- else {
- valueNumbering.insert(std::make_pair(V, nextValueNumber));
- return nextValueNumber++;
- }
- } else {
- valueNumbering.insert(std::make_pair(V, nextValueNumber));
- return nextValueNumber++;
- }
+ // Ignore non-local dependencies.
+ if (I->second.isNonLocal())
+ continue;
+
+ // We don't handle non-depedencies. If we already have a call, reject
+ // instruction dependencies.
+ if (I->second.isNone() || cdep != 0) {
+ cdep = 0;
+ break;
+ }
+
+ CallInst *NonLocalDepCall = dyn_cast<CallInst>(I->second.getInst());
+ // FIXME: All duplicated with non-local case.
+ if (NonLocalDepCall && DT->properlyDominates(I->first, C->getParent())){
+ cdep = NonLocalDepCall;
+ continue;
}
+
+ cdep = 0;
+ break;
}
if (!cdep) {
@@ -527,34 +532,28 @@
return nextValueNumber++;
}
- // FIXME: THIS ISN'T SAFE: CONSIDER:
- // X = strlen(str)
- // if (C)
- // str[0] = 1;
- // Y = strlen(str)
- // This doesn't guarantee all-paths availability!
if (cdep->getCalledFunction() != C->getCalledFunction() ||
cdep->getNumOperands() != C->getNumOperands()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
- } else if (!C->getCalledFunction()) {
+ }
+ if (!C->getCalledFunction()) {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
- } else {
- 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++;
- }
+ }
+ 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 = lookup_or_add(cdep);
- valueNumbering.insert(std::make_pair(V, v));
- return v;
}
+ uint32_t v = lookup_or_add(cdep);
+ valueNumbering.insert(std::make_pair(V, v));
+ return v;
+
} else {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
More information about the llvm-commits
mailing list