summaryrefslogtreecommitdiffstats
path: root/polly/lib
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2019-10-17 23:55:35 +0000
committerMichael Kruse <llvm@meinersbur.de>2019-10-17 23:55:35 +0000
commitd72637f5ccc43d457bfe227ccfe2eaa23936a37e (patch)
tree4d04bbfac4f03de71b9229621ace1b1ed982eb48 /polly/lib
parent8eaa5b9abab3a358353c3d925b1dd0b3a6ee4b42 (diff)
downloadbcm5719-llvm-d72637f5ccc43d457bfe227ccfe2eaa23936a37e.tar.gz
bcm5719-llvm-d72637f5ccc43d457bfe227ccfe2eaa23936a37e.zip
[ScopBuilder] Fix bug 38358 by preserving correct order of ScopStmts.
ScopBuilder::buildEqivClassBlockStmts creates ScopStmts for instruction groups in basic block and inserts these ScopStmts into Scop::StmtMap, however, as described in llvm.org/PR38358, comment #5, StmtScops are inserted into vector ScopStmt[BB] in wrong order. As a result, ScopBuilder::buildSchedule creates wrong order sequence node. Looking closer to code, it's clear there is no equivalent classes with interleaving isOrderedInstruction(memory access) instructions after joinOrderedInstructions. Afterwards, ScopStmts need to be created and inserted in the original order of memory access instructions, however, at the moment ScopStmts are inserted in the order of leader instructions which are probably not memory access instructions. The fix is simple with a standalone loop scanning isOrderedInstruction(memory access) instructions in basic block and inserting elements into LeaderToInstList one by one. The patch also removes double reversing operations which are now unnecessary. New test preserve-equiv-class-order-in-basic_block.ll is also added. Differential Revision: https://reviews.llvm.org/D68941 llvm-svn: 375192
Diffstat (limited to 'polly/lib')
-rw-r--r--polly/lib/Analysis/ScopBuilder.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 554e9a883ac..db7bea19176 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -2119,14 +2119,27 @@ void ScopBuilder::buildEqivClassBlockStmts(BasicBlock *BB) {
joinOrderedPHIs(UnionFind, ModeledInsts);
// The list of instructions for statement (statement represented by the leader
- // instruction). The order of statements instructions is reversed such that
- // the epilogue is first. This makes it easier to ensure that the epilogue is
- // the last statement.
+ // instruction).
MapVector<Instruction *, std::vector<Instruction *>> LeaderToInstList;
+ // The order of statements must be preserved w.r.t. their ordered
+ // instructions. Without this explicit scan, we would also use non-ordered
+ // instructions (whose order is arbitrary) to determine statement order.
+ for (Instruction &Inst : *BB) {
+ if (!isOrderedInstruction(&Inst))
+ continue;
+
+ auto LeaderIt = UnionFind.findLeader(&Inst);
+ if (LeaderIt == UnionFind.member_end())
+ continue;
+
+ // Insert element for the leader instruction.
+ (void)LeaderToInstList[*LeaderIt];
+ }
+
// Collect the instructions of all leaders. UnionFind's member iterator
// unfortunately are not in any specific order.
- for (Instruction &Inst : reverse(*BB)) {
+ for (Instruction &Inst : *BB) {
auto LeaderIt = UnionFind.findLeader(&Inst);
if (LeaderIt == UnionFind.member_end())
continue;
@@ -2140,13 +2153,12 @@ void ScopBuilder::buildEqivClassBlockStmts(BasicBlock *BB) {
// Finally build the statements.
int Count = 0;
long BBIdx = scop->getNextStmtIdx();
- for (auto &Instructions : reverse(LeaderToInstList)) {
+ for (auto &Instructions : LeaderToInstList) {
std::vector<Instruction *> &InstList = Instructions.second;
// If there is no main instruction, make the first statement the main.
bool IsMain = (MainInst ? MainLeader == Instructions.first : Count == 0);
- std::reverse(InstList.begin(), InstList.end());
std::string Name = makeStmtName(BB, BBIdx, Count, IsMain);
scop->addScopStmt(BB, Name, L, std::move(InstList));
Count += 1;
OpenPOWER on IntegriCloud