Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -736,6 +736,7 @@ } MinBWs.clear(); InstrElementSize.clear(); + NoCallInst = true; } unsigned getTreeSize() const { return VectorizableTree.size(); } @@ -2032,6 +2033,10 @@ /// A list of blocks that we are going to CSE. SetVector CSEBlocks; + /// The region of instruction that occupies VectorizableTree doesn't contain + /// any call instructions, indicating we don't need to calculate spill cost. + bool NoCallInst = true; + /// Contains all scheduling relevant data for an instruction. /// A ScheduleData either represents a single instruction or a member of an /// instruction bundle (= a group of instructions which is combined into a @@ -2181,8 +2186,8 @@ /// Contains all scheduling data for a basic block. struct BlockScheduling { - BlockScheduling(BasicBlock *BB) - : BB(BB), ChunkSize(BB->size()), ChunkPos(ChunkSize) {} + BlockScheduling(BasicBlock *BB, BoUpSLP *R) + : BB(BB), R(R), ChunkSize(BB->size()), ChunkPos(ChunkSize) {} void clear() { ReadyInsts.clear(); @@ -2367,6 +2372,8 @@ BasicBlock *BB; + BoUpSLP *R; + /// Simple memory allocation for ScheduleData. std::vector> ScheduleDataChunks; @@ -3305,7 +3312,7 @@ auto &BSRef = BlocksSchedules[BB]; if (!BSRef) - BSRef = std::make_unique(BB); + BSRef = std::make_unique(BB, this); BlockScheduling &BS = *BSRef.get(); @@ -5165,7 +5172,9 @@ } } - InstructionCost SpillCost = getSpillCost(); + InstructionCost SpillCost = 0; + if (!NoCallInst) + SpillCost = getSpillCost(); Cost += SpillCost + ExtractCost; for (int I = 0, E = FirstUsers.size(); I < E; ++I) { // For the very first element - simple shuffle of the source vector. @@ -6781,6 +6790,8 @@ } CurrentLoadStore = SD; } + if (isa(I)) + R->NoCallInst = false; } if (NextLoadStore) { if (CurrentLoadStore)