[llvm-commits] [llvm] r40540 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/2007-07-26-InterlockingLoops.ll test/Transforms/GVN/2007-07-26-PhiErasure.ll
Owen Anderson
resistor at mac.com
Thu Jul 26 11:26:51 PDT 2007
Author: resistor
Date: Thu Jul 26 13:26:51 2007
New Revision: 40540
URL: http://llvm.org/viewvc/llvm-project?rev=40540&view=rev
Log:
Fix a couple more bugs in the phi construction by pulling in code that does
almost the same things from LCSSA.
Added:
llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
llvm/trunk/test/Transforms/GVN/2007-07-26-PhiErasure.ll
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=40540&r1=40539&r2=40540&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Jul 26 13:26:51 2007
@@ -124,9 +124,6 @@
visited.erase(block);
- if (!inserted)
- resp.insert(std::make_pair(block, None));
-
return inserted;
}
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=40540&r1=40539&r2=40540&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Thu Jul 26 13:26:51 2007
@@ -13,12 +13,14 @@
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "gvn"
-#include "llvm/Value.h"
+
#include "llvm/Transforms/Scalar.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Instructions.h"
-#include "llvm/Function.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/Value.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
@@ -650,9 +652,8 @@
DenseMap<Value*, LoadInst*>& lastSeenLoad,
SmallVector<Instruction*, 4>& toErase);
bool processNonLocalLoad(LoadInst* L, SmallVector<Instruction*, 4>& toErase);
- Value *performPHIConstruction(BasicBlock *BB, LoadInst* orig,
- DenseMap<BasicBlock*, Value*> &Phis,
- SmallPtrSet<BasicBlock*, 4>& visited);
+ Value *GetValueForBlock(BasicBlock *BB, LoadInst* orig,
+ DenseMap<BasicBlock*, Value*> &Phis);
void dump(DenseMap<BasicBlock*, Value*>& d);
};
@@ -706,59 +707,35 @@
}
-Value *GVN::performPHIConstruction(BasicBlock *BB, LoadInst* orig,
- DenseMap<BasicBlock*, Value*> &Phis,
- SmallPtrSet<BasicBlock*, 4>& visited) {
- DenseMap<BasicBlock*, Value*>::iterator DI = Phis.find(BB);
- if (DI != Phis.end())
- return DI->second;
-
- unsigned numPreds = std::distance(pred_begin(BB), pred_end(BB));
-
- if (numPreds == 1) {
- DenseMap<BasicBlock*, Value*>::iterator DI = Phis.find(BB);
- if (DI != Phis.end()) {
- Phis.insert(std::make_pair(BB, DI->second));
- return DI->second;
- } else {
- visited.insert(BB);
- Value* domV = performPHIConstruction(*pred_begin(BB), orig, Phis, visited);
- visited.erase(BB);
-
- Phis.insert(std::make_pair(BB, domV));
- return domV;
- }
- } else {
- PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle", BB->begin());
- PN->reserveOperandSpace(numPreds);
- Phis[BB] = PN;
-
- visited.insert(BB);
- // Fill in the incoming values for the block.
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
- if (!visited.count(*PI))
- PN->addIncoming(performPHIConstruction(*PI, orig, Phis, visited), *PI);
- else {
- if (Phis[*PI])
- PN->addIncoming(Phis[*PI], *PI);
- else
- PN->addIncoming(PN, *PI);
- }
- visited.erase(BB);
-
- bool all_same = PN->getNumIncomingValues() != 1;
- Value* first = PN->getIncomingValue(0);
- for (unsigned i = 1; i < PN->getNumIncomingValues(); ++i)
- all_same &= (PN->getIncomingValue(i) == first);
-
- if (all_same) {
- PN->eraseFromParent();
- Phis[BB] = first;
- return first;
- } else {
- return PN;
- }
+/// GetValueForBlock - Get the value to use within the specified basic block.
+/// available values are in Phis.
+Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
+ DenseMap<BasicBlock*, Value*> &Phis) {
+ DominatorTree &DT = getAnalysis<DominatorTree>();
+
+ // If we have already computed this value, return the previously computed val.
+ Value *&V = Phis[BB];
+ if (V) return V;
+
+ DomTreeNode *IDom = DT.getNode(BB)->getIDom();
+
+ if (IDom && Phis.count(IDom->getBlock())) {
+ return V = GetValueForBlock(IDom->getBlock(), orig, Phis);
}
+
+
+
+ // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
+ // now, then get values to fill in the incoming values for the PHI.
+ PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle",
+ BB->begin());
+ PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
+ V = PN;
+
+ // Fill in the incoming values for the block.
+ for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
+ PN->addIncoming(GetValueForBlock(DT.getNode(*PI)->getBlock(), orig, Phis), *PI);
+ return PN;
}
bool GVN::processNonLocalLoad(LoadInst* L, SmallVector<Instruction*, 4>& toErase) {
@@ -789,7 +766,7 @@
}
SmallPtrSet<BasicBlock*, 4> visited;
- Value* v = performPHIConstruction(L->getParent(), L, repl, visited);
+ Value* v = GetValueForBlock(L->getParent(), L, repl);
MD.removeInstruction(L);
L->replaceAllUsesWith(v);
Added: llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll?rev=40540&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll (added)
+++ llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll Thu Jul 26 13:26:51 2007
@@ -0,0 +1,30 @@
+; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp17625 =}
+; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp17631 =}
+
+ at last = external global [65 x i32*] ; <[65 x i32*]*> [#uses=1]
+
+define i32 @NextRootMove(i32 %wtm) {
+cond_next95: ; preds = %cond_true85, %cond_true79, %cond_true73, %bb68
+ %tmp17618 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4 ; <i32*> [#uses=0]
+ br label %cond_true116
+
+cond_true116: ; preds = %cond_true111
+ br i1 false, label %cond_true128, label %cond_true145
+
+cond_true128: ; preds = %cond_true121
+ %tmp17625 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4 ; <i32*> [#uses=0]
+ br i1 false, label %bb98.backedge, label %return.loopexit
+
+bb98.backedge: ; preds = %bb171, %cond_true145, %cond_true128
+ br label %cond_true116
+
+cond_true145: ; preds = %cond_false
+ %tmp17631 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4 ; <i32*> [#uses=0]
+ br i1 false, label %bb98.backedge, label %return.loopexit
+
+return.loopexit: ; preds = %bb171, %cond_true145, %cond_true128
+ br label %return
+
+return: ; preds = %return.loopexit, %cond_next95, %cond_true85
+ ret i32 0
+}
Added: llvm/trunk/test/Transforms/GVN/2007-07-26-PhiErasure.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2007-07-26-PhiErasure.ll?rev=40540&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/2007-07-26-PhiErasure.ll (added)
+++ llvm/trunk/test/Transforms/GVN/2007-07-26-PhiErasure.ll Thu Jul 26 13:26:51 2007
@@ -0,0 +1,28 @@
+; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp298316 =}
+
+ %struct..0anon = type { i32 }
+ %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+ %struct.__sFILEX = type opaque
+ %struct.__sbuf = type { i8*, i32 }
+ %struct.rtx_def = type { i16, i8, i8, [1 x %struct..0anon] }
+ at n_spills = external global i32 ; <i32*> [#uses=2]
+
+define i32 @reload(%struct.rtx_def* %first, i32 %global, %struct.FILE* %dumpfile) {
+cond_next2835.1: ; preds = %cond_next2861
+ %tmp2922 = load i32* @n_spills, align 4 ; <i32> [#uses=0]
+ br label %bb2928
+
+bb2928: ; preds = %cond_next2835.1, %cond_next2943
+ br i1 false, label %cond_next2943, label %cond_true2935
+
+cond_true2935: ; preds = %bb2928
+ br label %cond_next2943
+
+cond_next2943: ; preds = %cond_true2935, %bb2928
+ br i1 false, label %bb2982.preheader, label %bb2928
+
+bb2982.preheader: ; preds = %cond_next2943
+ %tmp298316 = load i32* @n_spills, align 4 ; <i32> [#uses=0]
+ ret i32 0
+
+}
More information about the llvm-commits
mailing list