summaryrefslogtreecommitdiffstats
path: root/polly/lib/CodeGen/BlockGenerators.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'polly/lib/CodeGen/BlockGenerators.cpp')
-rw-r--r--polly/lib/CodeGen/BlockGenerators.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 5b576e1657d..bae65907a41 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -270,7 +270,8 @@ void BlockGenerator::copyInstruction(ScopStmt &Stmt, const Instruction *Inst,
Loop *L = getLoopForInst(Inst);
if ((Stmt.isBlockStmt() || !Stmt.getRegion()->contains(L)) &&
canSynthesize(Inst, &LI, &SE, &Stmt.getParent()->getRegion())) {
- // Synthesizable statements will be generated on-demand.
+ Value *NewValue = getNewValue(Stmt, Inst, BBMap, LTS, L);
+ BBMap[Inst] = NewValue;
return;
}
@@ -300,6 +301,28 @@ void BlockGenerator::copyInstruction(ScopStmt &Stmt, const Instruction *Inst,
copyInstScalar(Stmt, Inst, BBMap, LTS);
}
+/// @brief Remove trivially dead instructions from BB
+///
+/// This function drops trivially dead instructions from a basic block. It
+/// on purpose does _not_ recurse into other BBs even if the deletion of
+/// instructions in this basic block can make instructions in other basic blocks
+/// triviall dead.
+static void simplifyInstsInBlockOnly(BasicBlock *BB) {
+ auto BI = --BB->end(), BE = BB->begin();
+ bool Exit = false;
+ while (!Exit) {
+ auto ToRemove = BI;
+ if (BI != BE)
+ BI--;
+ else
+ Exit = true;
+
+ if (!isInstructionTriviallyDead(ToRemove))
+ continue;
+ ToRemove->eraseFromParent();
+ }
+}
+
void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
isl_id_to_ast_expr *NewAccesses) {
assert(Stmt.isBlockStmt() &&
@@ -309,6 +332,16 @@ void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
BasicBlock *BB = Stmt.getBasicBlock();
copyBB(Stmt, BB, BBMap, LTS, NewAccesses);
+
+ auto CopyBB = Builder.GetInsertBlock();
+ // Delete trivially dead instructions in CopyBB, but not in any other BB.
+ // Only for copyBB we know that there will _never_ be any future uses of
+ // instructions that have no use after copyBB has finished. Other instructions
+ // in the AST that have been generated by IslNodeBuilder may look dead at
+ // the moment, but may possibly still be referenced by GlobalMaps. If we
+ // delete them now, later uses would break surprisingly.
+ simplifyInstsInBlockOnly(CopyBB);
+ Builder.SetInsertPoint(CopyBB->getTerminator());
}
BasicBlock *BlockGenerator::splitBB(BasicBlock *BB) {
@@ -1099,6 +1132,15 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
LTS[L] = SE.getUnknown(LoopPHI);
}
+ // Delete trivially dead instructions in CopyBB, but not in any other BB.
+ // Only for copyBB we know that there will _never_ be any future uses of
+ // instructions that have no use after copyBB has finished. Other instructions
+ // in the AST that have been generated by IslNodeBuilder may look dead at
+ // the moment, but may possibly still be referenced by GlobalMaps. If we
+ // delete them now, later uses would break surprisingly.
+ for (auto *BB : SeenBlocks)
+ simplifyInstsInBlockOnly(BlockMap[BB]);
+
// Reset the old insert point for the build.
Builder.SetInsertPoint(ExitBBCopy->begin());
}
OpenPOWER on IntegriCloud