[PATCH] D22630: Loop rotation
Aditya Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 29 14:29:25 PDT 2016
hiraditya added inline comments.
================
Comment at: llvm/lib/Transforms/Scalar/LoopRotation.cpp:68-95
@@ -51,4 +67,30 @@
-namespace {
+static void insertBetween(BasicBlock *NewBB, BasicBlock *PredBefore,
+ BasicBlock *Succ) {
+ BranchInst *NewBI = BranchInst::Create(Succ, NewBB);
+ NewBI->setDebugLoc(PredBefore->getTerminator()->getDebugLoc());
+
+ BranchInst *BLI = dyn_cast<BranchInst>(PredBefore->getTerminator());
+ for (unsigned I = 0, E = BLI->getNumSuccessors(); I < E; ++I)
+ if (BLI->getSuccessor(I) == Succ) {
+ BLI->setSuccessor(I, NewBB);
+ break;
+ }
+ // Move NewBB physically from the end of the block list.
+ Function *F = Succ->getParent();
+ F->getBasicBlockList().splice(Succ->getIterator(), F->getBasicBlockList(),
+ NewBB);
+}
+
+// Remove the arguments of all phi nodes in PhiBB coming from block From.
+static void discardIncomingValues(BasicBlock *PhiBB, BasicBlock *From) {
+ for (Instruction &I : *PhiBB) {
+ PHINode *PN = dyn_cast<PHINode>(&I);
+ if (!PN)
+ break;
+ PN->removeIncomingValue(PN->getBasicBlockIndex(From));
+ }
+}
+
/// A simple loop rotation transformation.
class LoopRotate {
----------------
Using SplitEdge results in ICE because SplitEdge (for critical edges) tries to update PHI in a strange way. I think there is a bug in SplitEdge PHI update for single-entry PHIs. Moreover, loop-rotation needs to do its own PHI-update later anyways.
Specifically, BreakCriticalEdges:174, PN->getBasicBlockIndex may return -1, and threre is no check for that here.
if (PN->getIncomingBlock(BBIdx) != TIBB)
BBIdx = PN->getBasicBlockIndex(TIBB);
PN->setIncomingBlock(BBIdx, NewBB);
https://reviews.llvm.org/D22630
More information about the llvm-commits
mailing list