[llvm] r241741 - [LoopVectorizer] Restructurize code for emitting RT checks. NFCI.

Michael Zolotukhin mzolotukhin at apple.com
Wed Jul 8 14:47:59 PDT 2015


Author: mzolotukhin
Date: Wed Jul  8 16:47:59 2015
New Revision: 241741

URL: http://llvm.org/viewvc/llvm-project?rev=241741&view=rev
Log:
[LoopVectorizer] Restructurize code for emitting RT checks. NFCI.

Place all code corresponding to a run-time check in one place.
Previously we generated some code, then proceeded to a next check, then
finished the code for the first check (like splitting blocks and
generating branches). Now the code for generating a check is
self-contained.

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=241741&r1=241740&r2=241741&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Wed Jul  8 16:47:59 2015
@@ -2571,10 +2571,8 @@ void InnerLoopVectorizer::createEmptyLoo
   LoopBypassBlocks.push_back(BypassBlock);
 
   // Split the single block loop into the two loop structure described above.
-  BasicBlock *VectorPH =
-  BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph");
   BasicBlock *VecBody =
-  VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.body");
+      BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.body");
   BasicBlock *MiddleBlock =
   VecBody->splitBasicBlock(VecBody->getTerminator(), "middle.block");
   BasicBlock *ScalarPH =
@@ -2589,7 +2587,6 @@ void InnerLoopVectorizer::createEmptyLoo
   if (ParentLoop) {
     ParentLoop->addChildLoop(Lp);
     ParentLoop->addBasicBlockToLoop(ScalarPH, *LI);
-    ParentLoop->addBasicBlockToLoop(VectorPH, *LI);
     ParentLoop->addBasicBlockToLoop(MiddleBlock, *LI);
   } else {
     LI->addTopLevelLoop(Lp);
@@ -2613,7 +2610,6 @@ void InnerLoopVectorizer::createEmptyLoo
       BypassBlock->getTerminator(), "overflow.checked");
   if (ParentLoop)
     ParentLoop->addBasicBlockToLoop(CheckBlock, *LI);
-  LoopBypassBlocks.push_back(CheckBlock);
   ReplaceInstWithInst(
       BypassBlock->getTerminator(),
       BranchInst::Create(ScalarPH, CheckBlock, CheckBCOverflow));
@@ -2650,6 +2646,14 @@ void InnerLoopVectorizer::createEmptyLoo
   // jump to the scalar loop.
   Value *Cmp =
       BypassBuilder.CreateICmpEQ(IdxEndRoundDown, StartIdx, "cmp.zero");
+  CheckBlock =
+      BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph");
+  if (ParentLoop)
+    ParentLoop->addBasicBlockToLoop(CheckBlock, *LI);
+  LoopBypassBlocks.push_back(BypassBlock);
+  ReplaceInstWithInst(BypassBlock->getTerminator(),
+                      BranchInst::Create(MiddleBlock, CheckBlock, Cmp));
+  BypassBlock = CheckBlock;
 
   // Generate the code to check that the strides we assumed to be one are really
   // one. We want the new basic block to start at the first instruction in a
@@ -2661,18 +2665,19 @@ void InnerLoopVectorizer::createEmptyLoo
   if (StrideCheck) {
     AddedSafetyChecks = true;
     // Create a new block containing the stride check.
+    BypassBlock->setName("vector.stridecheck");
     BasicBlock *CheckBlock =
-        BypassBlock->splitBasicBlock(FirstCheckInst, "vector.stridecheck");
+        BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph");
     if (ParentLoop)
       ParentLoop->addBasicBlockToLoop(CheckBlock, *LI);
-    LoopBypassBlocks.push_back(CheckBlock);
+    LoopBypassBlocks.push_back(BypassBlock);
 
     // Replace the branch into the memory check block with a conditional branch
     // for the "few elements case".
-    ReplaceInstWithInst(BypassBlock->getTerminator(),
-                        BranchInst::Create(MiddleBlock, CheckBlock, Cmp));
+    ReplaceInstWithInst(
+        BypassBlock->getTerminator(),
+        BranchInst::Create(MiddleBlock, CheckBlock, StrideCheck));
 
-    Cmp = StrideCheck;
     BypassBlock = CheckBlock;
   }
 
@@ -2685,23 +2690,22 @@ void InnerLoopVectorizer::createEmptyLoo
   if (MemRuntimeCheck) {
     AddedSafetyChecks = true;
     // Create a new block containing the memory check.
+    BypassBlock->setName("vector.memcheck");
     BasicBlock *CheckBlock =
-        BypassBlock->splitBasicBlock(FirstCheckInst, "vector.memcheck");
+        BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph");
     if (ParentLoop)
       ParentLoop->addBasicBlockToLoop(CheckBlock, *LI);
-    LoopBypassBlocks.push_back(CheckBlock);
+    LoopBypassBlocks.push_back(BypassBlock);
 
     // Replace the branch into the memory check block with a conditional branch
     // for the "few elements case".
-    ReplaceInstWithInst(BypassBlock->getTerminator(),
-                        BranchInst::Create(MiddleBlock, CheckBlock, Cmp));
+    ReplaceInstWithInst(
+        BypassBlock->getTerminator(),
+        BranchInst::Create(MiddleBlock, CheckBlock, MemRuntimeCheck));
 
-    Cmp = MemRuntimeCheck;
     BypassBlock = CheckBlock;
   }
-
-  ReplaceInstWithInst(BypassBlock->getTerminator(),
-                      BranchInst::Create(MiddleBlock, VectorPH, Cmp));
+  BasicBlock *VectorPH = BypassBlock;
 
   // We are going to resume the execution of the scalar loop.
   // Go over all of the induction variables that we found and fix the





More information about the llvm-commits mailing list