From 9c42655c149d9c89db3165bff04e13aed34e53f5 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 24 Mar 2021 07:13:58 -0700 Subject: [PATCH] [SLP]Improve and simplify extendSchedulingRegion. We do not need to scan further if the upper end or lower end of the basic block is reached already and the instruction is not found. It means that the instruction is definitely in the lower part of basic block or in the upper block relatively. This should improve compile time for the very big basic blocks. Differential Revision: https://reviews.llvm.org/D99266 --- lib/Transforms/Vectorize/SLPVectorizer.cpp | 56 +++++++++---------- .../X86/crash_exceed_scheduling.ll | 6 +- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index d128312bc69..5c3d9d28fd8 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -5338,41 +5338,39 @@ bool BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V, BasicBlock::reverse_iterator UpperEnd = BB->rend(); BasicBlock::iterator DownIter = ScheduleEnd->getIterator(); BasicBlock::iterator LowerEnd = BB->end(); - while (true) { + while (UpIter != UpperEnd && DownIter != LowerEnd && &*UpIter != I && + &*DownIter != I) { if (++ScheduleRegionSize > ScheduleRegionSizeLimit) { LLVM_DEBUG(dbgs() << "SLP: exceeded schedule region size limit\n"); return false; } - if (UpIter != UpperEnd) { - if (&*UpIter == I) { - initScheduleData(I, ScheduleStart, nullptr, FirstLoadStoreInRegion); - ScheduleStart = I; - if (isOneOf(S, I) != I) - CheckSheduleForI(I); - LLVM_DEBUG(dbgs() << "SLP: extend schedule region start to " << *I - << "\n"); - return true; - } - ++UpIter; - } - if (DownIter != LowerEnd) { - if (&*DownIter == I) { - initScheduleData(ScheduleEnd, I->getNextNode(), LastLoadStoreInRegion, - nullptr); - ScheduleEnd = I->getNextNode(); - if (isOneOf(S, I) != I) - CheckSheduleForI(I); - assert(ScheduleEnd && "tried to vectorize a terminator?"); - LLVM_DEBUG(dbgs() << "SLP: extend schedule region end to " << *I - << "\n"); - return true; - } - ++DownIter; - } - assert((UpIter != UpperEnd || DownIter != LowerEnd) && - "instruction not found in block"); + ++UpIter; + ++DownIter; } + if (DownIter == LowerEnd || (UpIter != UpperEnd && &*UpIter == I)) { + assert(I->getParent() == ScheduleStart->getParent() && + "Instruction is in wrong basic block."); + initScheduleData(I, ScheduleStart, nullptr, FirstLoadStoreInRegion); + ScheduleStart = I; + if (isOneOf(S, I) != I) + CheckSheduleForI(I); + LLVM_DEBUG(dbgs() << "SLP: extend schedule region start to " << *I + << "\n"); + return true; + } + assert((UpIter == UpperEnd || (DownIter != LowerEnd && &*DownIter == I)) && + "Expected to reach top of the basic block or instruction down the " + "lower end."); + assert(I->getParent() == ScheduleEnd->getParent() && + "Instruction is in wrong basic block."); + initScheduleData(ScheduleEnd, I->getNextNode(), LastLoadStoreInRegion, + nullptr); + ScheduleEnd = I->getNextNode(); + if (isOneOf(S, I) != I) + CheckSheduleForI(I); + assert(ScheduleEnd && "tried to vectorize a terminator?"); + LLVM_DEBUG(dbgs() << "SLP: extend schedule region end to " << *I << "\n"); return true; } diff --git a/test/Transforms/SLPVectorizer/X86/crash_exceed_scheduling.ll b/test/Transforms/SLPVectorizer/X86/crash_exceed_scheduling.ll index 299c2d3642c..14d6920424e 100644 --- a/test/Transforms/SLPVectorizer/X86/crash_exceed_scheduling.ll +++ b/test/Transforms/SLPVectorizer/X86/crash_exceed_scheduling.ll @@ -44,13 +44,9 @@ define void @exceed(double %0, double %1) { ; CHECK: bb1: ; CHECK-NEXT: br label [[LABEL:%.*]] ; CHECK: bb2: -; CHECK-NEXT: [[TMP17:%.*]] = extractelement <2 x double> [[TMP16]], i32 0 -; CHECK-NEXT: [[TMP18:%.*]] = insertelement <2 x double> poison, double [[TMP17]], i32 0 -; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x double> [[TMP16]], i32 1 -; CHECK-NEXT: [[TMP20:%.*]] = insertelement <2 x double> [[TMP18]], double [[TMP19]], i32 1 ; CHECK-NEXT: br label [[LABEL]] ; CHECK: label: -; CHECK-NEXT: [[TMP21:%.*]] = phi <2 x double> [ [[TMP12]], [[BB1]] ], [ [[TMP20]], [[BB2]] ] +; CHECK-NEXT: [[TMP17:%.*]] = phi <2 x double> [ [[TMP12]], [[BB1]] ], [ [[TMP16]], [[BB2]] ] ; CHECK-NEXT: ret void ; entry: