[llvm] e66127e - [VPlan] Simplify & adjust code as suggested in D123005.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 05:35:15 PDT 2022


Author: Florian Hahn
Date: 2022-04-29T13:34:54+01:00
New Revision: e66127e69bfabe1b18857c3e3962125a9fe5aa7c

URL: https://github.com/llvm/llvm-project/commit/e66127e69bfabe1b18857c3e3962125a9fe5aa7c
DIFF: https://github.com/llvm/llvm-project/commit/e66127e69bfabe1b18857c3e3962125a9fe5aa7c.diff

LOG: [VPlan] Simplify & adjust code as suggested in D123005.

Improve code as suggested in D123005. Applied separately, because the
comments where made a diff that has not been rebased to current main.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlan.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 73f4903e1a39..02550dadcd02 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -283,32 +283,34 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
     LLVM_DEBUG(dbgs() << "LV: draw edge from" << PredBB->getName() << '\n');
 
     auto *TermBr = dyn_cast<BranchInst>(PredBBTerminator);
-    if (isa<UnreachableInst>(PredBBTerminator) ||
-        (TermBr && !TermBr->isConditional())) {
+    if (isa<UnreachableInst>(PredBBTerminator)) {
       assert(PredVPSuccessors.size() == 1 &&
              "Predecessor ending w/o branch must have single successor.");
-      if (TermBr) {
-        TermBr->setSuccessor(0, NewBB);
-      } else {
-        DebugLoc DL = PredBBTerminator->getDebugLoc();
-        PredBBTerminator->eraseFromParent();
-        auto *Br = BranchInst::Create(NewBB, PredBB);
-        Br->setDebugLoc(DL);
-      }
+      DebugLoc DL = PredBBTerminator->getDebugLoc();
+      PredBBTerminator->eraseFromParent();
+      auto *Br = BranchInst::Create(NewBB, PredBB);
+      Br->setDebugLoc(DL);
+    } else if (TermBr && !TermBr->isConditional()) {
+      TermBr->setSuccessor(0, NewBB);
+    } else if (PredVPSuccessors.size() == 2) {
+      unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
+      assert(!PredBBTerminator->getSuccessor(idx) &&
+             "Trying to reset an existing successor block.");
+      PredBBTerminator->setSuccessor(idx, NewBB);
     } else {
-      if (PredVPSuccessors.size() == 2) {
-        unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
-        assert(!PredBBTerminator->getSuccessor(idx) &&
-               "Trying to reset an existing successor block.");
-        PredBBTerminator->setSuccessor(idx, NewBB);
-      } else {
-        auto *Reg = dyn_cast<VPRegionBlock>(PredVPBB->getParent());
-        assert(Reg && !Reg->isReplicator());
-        assert(this == Reg->getSingleSuccessor());
-        PredBBTerminator->setSuccessor(0, NewBB);
-        PredBBTerminator->setSuccessor(
-            1, CFG.VPBB2IRBB[Reg->getEntryBasicBlock()]);
-      }
+      // PredVPBB is the exit block of a loop region. Connect its successor
+      // outside the region.
+      auto *LoopRegion = cast<VPRegionBlock>(PredVPBB->getParent());
+      assert(!LoopRegion->isReplicator() &&
+             "predecessor must be in a loop region");
+      assert(PredVPSuccessors.empty() &&
+             LoopRegion->getExitBasicBlock() == PredVPBB &&
+             "PredVPBB must be the exit block of its parent region");
+      assert(this == LoopRegion->getSingleSuccessor() &&
+             "the current block must be the single successor of the region");
+      PredBBTerminator->setSuccessor(0, NewBB);
+      PredBBTerminator->setSuccessor(
+          1, CFG.VPBB2IRBB[LoopRegion->getEntryBasicBlock()]);
     }
   }
   return NewBB;
@@ -320,7 +322,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
   VPBlockBase *SingleHPred = nullptr;
   BasicBlock *NewBB = State->CFG.PrevBB; // Reuse it if possible.
 
-  auto IsNonReplicateR = [](VPBlockBase *BB) {
+  auto IsLoopRegion = [](VPBlockBase *BB) {
     auto *R = dyn_cast<VPRegionBlock>(BB);
     return R && !R->isReplicator();
   };
@@ -335,7 +337,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
                SingleHPred->getExitBasicBlock() == PrevVPBB &&
                PrevVPBB->getSingleHierarchicalSuccessor() &&
                (SingleHPred->getParent() == getEnclosingLoopRegion() &&
-                !IsNonReplicateR(SingleHPred))) &&      /* B */
+                !IsLoopRegion(SingleHPred))) &&         /* B */
              !(Replica && getPredecessors().empty())) { /* C */
     // The last IR basic block is reused, as an optimization, in three cases:
     // A. the first VPBB reuses the loop pre-header BB - when PrevVPBB is null;


        


More information about the llvm-commits mailing list