Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6175,6 +6175,9 @@ float Cost = expectedCost(1).first; const float ScalarCost = Cost; unsigned Width = 1; + float MinVectCost ; + unsigned BestVectCostWidth ; + unsigned Count = 0; DEBUG(dbgs() << "LV: Scalar loop costs: " << (int)ScalarCost << ".\n"); bool ForceVectorization = Hints->getForce() == LoopVectorizeHints::FK_Enabled; @@ -6198,10 +6201,20 @@ << " because it will not generate any vector instructions.\n"); continue; } + Count +=1; if (VectorCost < Cost) { Cost = VectorCost; Width = i; } + if(Count==1) { + MinVectCost = Cost; + BestVectCostWidth = Width; + continue; + } + if(VectorCost < MinVectCost) { + MinVectCost = VectorCost; + BestVectCostWidth = i; + } } if (!EnableCondStoresVectorization && NumPredStores) { @@ -6212,6 +6225,23 @@ Cost = ScalarCost; } + if(MaxVF >=2) { + if(Count >=1) { + ORE->emit([&]() { + return OptimizationRemarkAnalysis(Hints->vectorizeAnalysisPassName(), "VectorizationNotBeneficial", + TheLoop->getStartLoc(), TheLoop->getHeader()) + << "The best vector cost is : " << StringRef(std::to_string(MinVectCost)) << " with vector width : " << StringRef(std::to_string(BestVectCostWidth))<< ", Scalar loop costs: " << StringRef(std::to_string(ScalarCost)) ; + }); + } + else { + ORE->emit([&]() { + return OptimizationRemarkAnalysis(Hints->vectorizeAnalysisPassName(), "VectorizationNotBeneficial", + TheLoop->getStartLoc(), TheLoop->getHeader()) + << " none of the width generate any vector instructions " ; + }); + } + } + DEBUG(if (ForceVectorization && Width > 1 && Cost >= ScalarCost) dbgs() << "LV: Vectorization seems to be not beneficial, " << "but was forced by a user.\n");