[llvm-commits] [llvm] r119853 - /llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
Owen Anderson
resistor at mac.com
Fri Nov 19 14:15:03 PST 2010
Author: resistor
Date: Fri Nov 19 16:15:03 2010
New Revision: 119853
URL: http://llvm.org/viewvc/llvm-project?rev=119853&view=rev
Log:
When folding addressing modes in CodeGenPrepare, attempt to look through PHI nodes
if all the operands of the PHI are equivalent. This allows CodeGenPrepare to undo
unprofitable PRE transforms.
Modified:
llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=119853&r1=119852&r2=119853&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Fri Nov 19 16:15:03 2010
@@ -618,6 +618,32 @@
bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
const Type *AccessTy,
DenseMap<Value*,Value*> &SunkAddrs) {
+ // Try to collapse single-value PHI nodes. This is necessary to undo
+ // unprofitable PRE transformations.
+ Value *Repl = Addr;
+ if (isa<PHINode>(Addr) && MemoryInst->hasOneUse()) {
+ PHINode *P = cast<PHINode>(Addr);
+ Instruction *Consensus = 0;
+ unsigned NumUses = 0;
+ for (unsigned i = 0, e = P->getNumIncomingValues(); i != e; ++i) {
+ Instruction *Incoming = dyn_cast<Instruction>(P->getIncomingValue(i));
+ if (!Incoming || (Consensus && !Incoming->isIdenticalTo(Consensus))) {
+ Consensus = 0;
+ break;
+ }
+
+ if (!Consensus || Incoming->isIdenticalTo(Consensus)) {
+ if (Incoming->getNumUses() > NumUses) {
+ Consensus = Incoming;
+ NumUses = Incoming->getNumUses();
+ }
+ continue;
+ }
+ }
+
+ if (Consensus) Addr = Consensus;
+ }
+
// Figure out what addressing mode will be built up for this operation.
SmallVector<Instruction*, 16> AddrModeInsts;
ExtAddrMode AddrMode = AddressingModeMatcher::Match(Addr, AccessTy,MemoryInst,
@@ -725,10 +751,10 @@
SunkAddr = new IntToPtrInst(Result, Addr->getType(), "sunkaddr",InsertPt);
}
- MemoryInst->replaceUsesOfWith(Addr, SunkAddr);
+ MemoryInst->replaceUsesOfWith(Repl, SunkAddr);
- if (Addr->use_empty()) {
- RecursivelyDeleteTriviallyDeadInstructions(Addr);
+ if (Repl->use_empty()) {
+ RecursivelyDeleteTriviallyDeadInstructions(Repl);
// This address is now available for reassignment, so erase the table entry;
// we don't want to match some completely different instruction.
SunkAddrs[Addr] = 0;
More information about the llvm-commits
mailing list