Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2637,6 +2637,7 @@ // Make a new scheduling region, i.e. all existing ScheduleData is not // in the new region yet. ++SchedulingRegionID; + NoCalls = true; } ScheduleData *getScheduleData(Value *V) { @@ -2877,6 +2878,10 @@ // Make sure that the initial SchedulingRegionID is greater than the // initial SchedulingRegionID in ScheduleData (which is 0). int SchedulingRegionID = 1; + + /// Indicates that no CallInst found in the tree and we don't need to + /// calculate spill cost. + bool NoCalls = true; }; /// Attaches the BlockScheduling structures to basic blocks. @@ -5804,10 +5809,11 @@ } // Debug information does not impact spill cost. - if ((isa(&*PrevInstIt) && - !isa(&*PrevInstIt)) && - &*PrevInstIt != PrevInst) - NumCalls++; + if (isa(&*PrevInstIt)) { + auto *II = dyn_cast(&*PrevInstIt); + if (!II || !II->isAssumeLikeIntrinsic()) + NumCalls++; + } ++PrevInstIt; } @@ -5968,7 +5974,13 @@ } } - InstructionCost SpillCost = getSpillCost(); + bool NoCallInst = all_of(BlocksSchedules, + [](const decltype(BlocksSchedules)::value_type &BS) { + return BS.second->NoCalls; + }); + + InstructionCost SpillCost = NoCallInst ? 0 : getSpillCost(); + assert((!NoCallInst || getSpillCost() == 0) && "Incorrect spill cost"); Cost += SpillCost + ExtractCost; if (FirstUsers.size() == 1) { int Limit = ShuffleMask.front().size() * 2; @@ -7748,6 +7760,11 @@ } CurrentLoadStore = SD; } + if (isa(I)) { + auto *II = dyn_cast(I); + if (!II || !II->isAssumeLikeIntrinsic()) + NoCalls = false; + } } if (NextLoadStore) { if (CurrentLoadStore)