[LoopVectorizer] Rename BypassBlock to VectorPH, and CheckBlock to NewVectorPH. NFCI.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241742 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Zolotukhin
2015-07-08 21:48:03 +00:00
parent c196e8f18b
commit 5ebb47fa90

View File

@ -2503,9 +2503,9 @@ void InnerLoopVectorizer::createEmptyLoop() {
*/ */
BasicBlock *OldBasicBlock = OrigLoop->getHeader(); BasicBlock *OldBasicBlock = OrigLoop->getHeader();
BasicBlock *BypassBlock = OrigLoop->getLoopPreheader(); BasicBlock *VectorPH = OrigLoop->getLoopPreheader();
BasicBlock *ExitBlock = OrigLoop->getExitBlock(); BasicBlock *ExitBlock = OrigLoop->getExitBlock();
assert(BypassBlock && "Invalid loop structure"); assert(VectorPH && "Invalid loop structure");
assert(ExitBlock && "Must have an exit block"); assert(ExitBlock && "Must have an exit block");
// Some loops have a single integer induction variable, while other loops // Some loops have a single integer induction variable, while other loops
@ -2545,34 +2545,35 @@ void InnerLoopVectorizer::createEmptyLoop() {
// loop. // loop.
Value *BackedgeCount = Value *BackedgeCount =
Exp.expandCodeFor(BackedgeTakeCount, BackedgeTakeCount->getType(), Exp.expandCodeFor(BackedgeTakeCount, BackedgeTakeCount->getType(),
BypassBlock->getTerminator()); VectorPH->getTerminator());
if (BackedgeCount->getType()->isPointerTy()) if (BackedgeCount->getType()->isPointerTy())
BackedgeCount = CastInst::CreatePointerCast(BackedgeCount, IdxTy, BackedgeCount = CastInst::CreatePointerCast(BackedgeCount, IdxTy,
"backedge.ptrcnt.to.int", "backedge.ptrcnt.to.int",
BypassBlock->getTerminator()); VectorPH->getTerminator());
Instruction *CheckBCOverflow = Instruction *CheckBCOverflow =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, BackedgeCount, CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, BackedgeCount,
Constant::getAllOnesValue(BackedgeCount->getType()), Constant::getAllOnesValue(BackedgeCount->getType()),
"backedge.overflow", BypassBlock->getTerminator()); "backedge.overflow", VectorPH->getTerminator());
// The loop index does not have to start at Zero. Find the original start // The loop index does not have to start at Zero. Find the original start
// value from the induction PHI node. If we don't have an induction variable // value from the induction PHI node. If we don't have an induction variable
// then we know that it starts at zero. // then we know that it starts at zero.
Builder.SetInsertPoint(BypassBlock->getTerminator()); Builder.SetInsertPoint(VectorPH->getTerminator());
Value *StartIdx = ExtendedIdx = OldInduction ? Value *StartIdx = ExtendedIdx =
Builder.CreateZExt(OldInduction->getIncomingValueForBlock(BypassBlock), OldInduction
IdxTy): ? Builder.CreateZExt(OldInduction->getIncomingValueForBlock(VectorPH),
ConstantInt::get(IdxTy, 0); IdxTy)
: ConstantInt::get(IdxTy, 0);
// Count holds the overall loop count (N). // Count holds the overall loop count (N).
Value *Count = Exp.expandCodeFor(ExitCount, ExitCount->getType(), Value *Count = Exp.expandCodeFor(ExitCount, ExitCount->getType(),
BypassBlock->getTerminator()); VectorPH->getTerminator());
LoopBypassBlocks.push_back(BypassBlock); LoopBypassBlocks.push_back(VectorPH);
// Split the single block loop into the two loop structure described above. // Split the single block loop into the two loop structure described above.
BasicBlock *VecBody = BasicBlock *VecBody =
BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.body"); VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.body");
BasicBlock *MiddleBlock = BasicBlock *MiddleBlock =
VecBody->splitBasicBlock(VecBody->getTerminator(), "middle.block"); VecBody->splitBasicBlock(VecBody->getTerminator(), "middle.block");
BasicBlock *ScalarPH = BasicBlock *ScalarPH =
@ -2606,18 +2607,18 @@ void InnerLoopVectorizer::createEmptyLoop() {
// Generate code to check that the loop's trip count that we computed by // Generate code to check that the loop's trip count that we computed by
// adding one to the backedge-taken count will not overflow. // adding one to the backedge-taken count will not overflow.
BasicBlock *CheckBlock = BypassBlock->splitBasicBlock( BasicBlock *NewVectorPH =
BypassBlock->getTerminator(), "overflow.checked"); VectorPH->splitBasicBlock(VectorPH->getTerminator(), "overflow.checked");
if (ParentLoop) if (ParentLoop)
ParentLoop->addBasicBlockToLoop(CheckBlock, *LI); ParentLoop->addBasicBlockToLoop(NewVectorPH, *LI);
ReplaceInstWithInst( ReplaceInstWithInst(
BypassBlock->getTerminator(), VectorPH->getTerminator(),
BranchInst::Create(ScalarPH, CheckBlock, CheckBCOverflow)); BranchInst::Create(ScalarPH, NewVectorPH, CheckBCOverflow));
BypassBlock = CheckBlock; VectorPH = NewVectorPH;
// This is the IR builder that we use to add all of the logic for bypassing // This is the IR builder that we use to add all of the logic for bypassing
// the new vector loop. // the new vector loop.
IRBuilder<> BypassBuilder(BypassBlock->getTerminator()); IRBuilder<> BypassBuilder(VectorPH->getTerminator());
setDebugLocFromInst(BypassBuilder, setDebugLocFromInst(BypassBuilder,
getDebugLocFromInstOrOperands(OldInduction)); getDebugLocFromInstOrOperands(OldInduction));
@ -2646,14 +2647,14 @@ void InnerLoopVectorizer::createEmptyLoop() {
// jump to the scalar loop. // jump to the scalar loop.
Value *Cmp = Value *Cmp =
BypassBuilder.CreateICmpEQ(IdxEndRoundDown, StartIdx, "cmp.zero"); BypassBuilder.CreateICmpEQ(IdxEndRoundDown, StartIdx, "cmp.zero");
CheckBlock = NewVectorPH =
BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph"); VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.ph");
if (ParentLoop) if (ParentLoop)
ParentLoop->addBasicBlockToLoop(CheckBlock, *LI); ParentLoop->addBasicBlockToLoop(NewVectorPH, *LI);
LoopBypassBlocks.push_back(BypassBlock); LoopBypassBlocks.push_back(VectorPH);
ReplaceInstWithInst(BypassBlock->getTerminator(), ReplaceInstWithInst(VectorPH->getTerminator(),
BranchInst::Create(MiddleBlock, CheckBlock, Cmp)); BranchInst::Create(MiddleBlock, NewVectorPH, Cmp));
BypassBlock = CheckBlock; VectorPH = NewVectorPH;
// Generate the code to check that the strides we assumed to be one are really // 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 // one. We want the new basic block to start at the first instruction in a
@ -2661,24 +2662,24 @@ void InnerLoopVectorizer::createEmptyLoop() {
Instruction *StrideCheck; Instruction *StrideCheck;
Instruction *FirstCheckInst; Instruction *FirstCheckInst;
std::tie(FirstCheckInst, StrideCheck) = std::tie(FirstCheckInst, StrideCheck) =
addStrideCheck(BypassBlock->getTerminator()); addStrideCheck(VectorPH->getTerminator());
if (StrideCheck) { if (StrideCheck) {
AddedSafetyChecks = true; AddedSafetyChecks = true;
// Create a new block containing the stride check. // Create a new block containing the stride check.
BypassBlock->setName("vector.stridecheck"); VectorPH->setName("vector.stridecheck");
BasicBlock *CheckBlock = NewVectorPH =
BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph"); VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.ph");
if (ParentLoop) if (ParentLoop)
ParentLoop->addBasicBlockToLoop(CheckBlock, *LI); ParentLoop->addBasicBlockToLoop(NewVectorPH, *LI);
LoopBypassBlocks.push_back(BypassBlock); LoopBypassBlocks.push_back(VectorPH);
// Replace the branch into the memory check block with a conditional branch // Replace the branch into the memory check block with a conditional branch
// for the "few elements case". // for the "few elements case".
ReplaceInstWithInst( ReplaceInstWithInst(
BypassBlock->getTerminator(), VectorPH->getTerminator(),
BranchInst::Create(MiddleBlock, CheckBlock, StrideCheck)); BranchInst::Create(MiddleBlock, NewVectorPH, StrideCheck));
BypassBlock = CheckBlock; VectorPH = NewVectorPH;
} }
// Generate the code that checks in runtime if arrays overlap. We put the // Generate the code that checks in runtime if arrays overlap. We put the
@ -2686,26 +2687,25 @@ void InnerLoopVectorizer::createEmptyLoop() {
// faster. // faster.
Instruction *MemRuntimeCheck; Instruction *MemRuntimeCheck;
std::tie(FirstCheckInst, MemRuntimeCheck) = std::tie(FirstCheckInst, MemRuntimeCheck) =
Legal->getLAI()->addRuntimeCheck(BypassBlock->getTerminator()); Legal->getLAI()->addRuntimeCheck(VectorPH->getTerminator());
if (MemRuntimeCheck) { if (MemRuntimeCheck) {
AddedSafetyChecks = true; AddedSafetyChecks = true;
// Create a new block containing the memory check. // Create a new block containing the memory check.
BypassBlock->setName("vector.memcheck"); VectorPH->setName("vector.memcheck");
BasicBlock *CheckBlock = NewVectorPH =
BypassBlock->splitBasicBlock(BypassBlock->getTerminator(), "vector.ph"); VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.ph");
if (ParentLoop) if (ParentLoop)
ParentLoop->addBasicBlockToLoop(CheckBlock, *LI); ParentLoop->addBasicBlockToLoop(NewVectorPH, *LI);
LoopBypassBlocks.push_back(BypassBlock); LoopBypassBlocks.push_back(VectorPH);
// Replace the branch into the memory check block with a conditional branch // Replace the branch into the memory check block with a conditional branch
// for the "few elements case". // for the "few elements case".
ReplaceInstWithInst( ReplaceInstWithInst(
BypassBlock->getTerminator(), VectorPH->getTerminator(),
BranchInst::Create(MiddleBlock, CheckBlock, MemRuntimeCheck)); BranchInst::Create(MiddleBlock, NewVectorPH, MemRuntimeCheck));
BypassBlock = CheckBlock; VectorPH = NewVectorPH;
} }
BasicBlock *VectorPH = BypassBlock;
// We are going to resume the execution of the scalar loop. // We are going to resume the execution of the scalar loop.
// Go over all of the induction variables that we found and fix the // Go over all of the induction variables that we found and fix the