summaryrefslogtreecommitdiff
path: root/polly/lib/CodeGen/BlockGenerators.cpp
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2017-01-19 14:12:45 +0000
committerTobias Grosser <tobias@grosser.es>2017-01-19 14:12:45 +0000
commit75dfaa1dbe4c56db70698317db28822a553e2382 (patch)
tree220a6507581d555d4381640ee8f4f8ee28980741 /polly/lib/CodeGen/BlockGenerators.cpp
parent2074e7497b6e69c3925216405bc69e8c125036e5 (diff)
BlockGenerator: Do not redundantly reload from PHI-allocas in non-affine stmts
Before this change we created an additional reload in the copy of the incoming block of a PHI node to reload the incoming value, even though the necessary value has already been made available by the normally generated scalar loads. In this change, we drop the code that generates this redundant reload and instead just reuse the scalar value already available. Besides making the generated code slightly cleaner, this change also makes sure that scalar loads go through the normal logic, which means they can be remapped (e.g. to array slots) and corresponding code is generated to load from the remapped location. Without this change, the original scalar load at the beginning of the non-affine region would have been remapped, but the redundant scalar load would continue to load from the old PHI slot location. It might be possible to further simplify the code in addOperandToPHI, but this would not only mean to pull out getNewValue, but to also change the insertion point update logic. As this did not work when trying it the first time, this change is likely not trivial. To not introduce bugs last minute, we postpone further simplications to a subsequent commit. We also document the current behavior a little bit better. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D28892 llvm-svn: 292486
Diffstat (limited to 'polly/lib/CodeGen/BlockGenerators.cpp')
-rw-r--r--polly/lib/CodeGen/BlockGenerators.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 46a066a10869..25622378ca74 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -1415,12 +1415,12 @@ void RegionGenerator::addOperandToPHI(ScopStmt &Stmt, PHINode *PHI,
return;
}
+ assert(RegionMaps.count(BBCopy) && "Incoming PHI block did not have a BBMap");
+ ValueMapT &BBCopyMap = RegionMaps[BBCopy];
+
Value *OpCopy = nullptr;
- if (StmtR->contains(IncomingBB)) {
- assert(RegionMaps.count(BBCopy) &&
- "Incoming PHI block did not have a BBMap");
- ValueMapT &BBCopyMap = RegionMaps[BBCopy];
+ if (StmtR->contains(IncomingBB)) {
Value *Op = PHI->getIncomingValueForBlock(IncomingBB);
// If the current insert block is different from the PHIs incoming block
@@ -1432,13 +1432,15 @@ void RegionGenerator::addOperandToPHI(ScopStmt &Stmt, PHINode *PHI,
if (IP->getParent() != BBCopy)
Builder.SetInsertPoint(&*IP);
} else {
-
+ // All edges from outside the non-affine region become a single edge
+ // in the new copy of the non-affine region. Make sure to only add the
+ // corresponding edge the first time we encounter a basic block from
+ // outside the non-affine region.
if (PHICopy->getBasicBlockIndex(BBCopy) >= 0)
return;
- Value *PHIOpAddr = getOrCreatePHIAlloca(PHI);
- OpCopy = new LoadInst(PHIOpAddr, PHIOpAddr->getName() + ".reload",
- BlockMap[IncomingBB]->getTerminator());
+ // Get the reloaded value.
+ OpCopy = getNewValue(Stmt, PHI, BBCopyMap, LTS, getLoopForStmt(Stmt));
}
assert(OpCopy && "Incoming PHI value was not copied properly");