diff options
-rw-r--r-- | polly/include/polly/ScopInfo.h | 26 | ||||
-rw-r--r-- | polly/lib/Analysis/ScopInfo.cpp | 13 | ||||
-rw-r--r-- | polly/lib/Transform/DeLICM.cpp | 9 |
3 files changed, 42 insertions, 6 deletions
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index fbaa5a83b59..32b61b70b52 100644 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -1422,6 +1422,10 @@ public: return ValueReads.lookup(Inst); } + /// Return the MemoryAccess that loads a PHINode value, or nullptr if not + /// existing, respectively not yet added. + MemoryAccess *lookupPHIReadOf(PHINode *PHI) const; + /// Return the PHI write MemoryAccess for the incoming values from any /// basic block in this ScopStmt, or nullptr if not existing, /// respectively not yet added. @@ -1430,6 +1434,28 @@ public: return PHIWrites.lookup(PHI); } + /// Return the input access of the value, or null if no such MemoryAccess + /// exists. + /// + /// The input access is the MemoryAccess that makes an inter-statement value + /// available in this statement by reading it at the start of this statement. + /// This can be a MemoryKind::Value if defined in another statement or a + /// MemoryKind::PHI if the value is a PHINode in this statement. + MemoryAccess *lookupInputAccessOf(Value *Val) const { + if (isa<PHINode>(Val)) + if (auto InputMA = lookupPHIReadOf(cast<PHINode>(Val))) { + assert(!lookupValueReadOf(Val) && "input accesses must be unique; a " + "statement cannot read a .s2a and " + ".phiops simultaneously"); + return InputMA; + } + + if (auto *InputMA = lookupValueReadOf(Val)) + return InputMA; + + return nullptr; + } + /// Add @p Access to this statement's list of accesses. void addAccess(MemoryAccess *Access); diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index a5406100bf0..462ff6314f8 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -1285,6 +1285,19 @@ void ScopStmt::buildAccessRelations() { } } +MemoryAccess *ScopStmt::lookupPHIReadOf(PHINode *PHI) const { + for (auto *MA : *this) { + if (!MA->isRead()) + continue; + if (!MA->isLatestAnyPHIKind()) + continue; + + if (MA->getAccessInstruction() == PHI) + return MA; + } + return nullptr; +} + void ScopStmt::addAccess(MemoryAccess *Access) { Instruction *AccessInst = Access->getAccessInstruction(); diff --git a/polly/lib/Transform/DeLICM.cpp b/polly/lib/Transform/DeLICM.cpp index 72abb088845..7bcb0726632 100644 --- a/polly/lib/Transform/DeLICM.cpp +++ b/polly/lib/Transform/DeLICM.cpp @@ -1949,12 +1949,9 @@ private: } }; - // Add initial scalar. Either the value written by the store, or all inputs - // of its statement. - auto WrittenValUse = VirtualUse::create( - S, TargetStoreMA->getAccessInstruction()->getOperandUse(0), LI, true); - if (WrittenValUse.isInter()) - Worklist.push_back(WrittenValUse.getMemoryAccess()); + auto *WrittenVal = TargetStoreMA->getAccessInstruction()->getOperand(0); + if (auto *WrittenValInputMA = TargetStmt->lookupInputAccessOf(WrittenVal)) + Worklist.push_back(WrittenValInputMA); else ProcessAllIncoming(TargetStmt); |