diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5834,7 +5834,7 @@ LLVM_DEBUG(dbgs() << "LV: Scalar loop costs: " << ExpectedCost << ".\n"); assert(ExpectedCost.isValid() && "Unexpected invalid cost for scalar loop"); - unsigned Width = 1; + auto Width = ElementCount::getFixed(1); const float ScalarCost = *ExpectedCost.getValue(); float Cost = ScalarCost; @@ -5846,13 +5846,14 @@ Cost = std::numeric_limits::max(); } - for (unsigned i = 2; i <= MaxVF.getFixedValue(); i *= 2) { + for (auto i = ElementCount::getFixed(2); ElementCount::isKnownLE(i, MaxVF); + i *= 2) { // Notice that the vector loop needs to be executed less times, so // we need to divide the cost of the vector loops by the width of // the vector elements. - VectorizationCostTy C = expectedCost(ElementCount::getFixed(i)); + VectorizationCostTy C = expectedCost(i); assert(C.first.isValid() && "Unexpected invalid cost for vector loop"); - float VectorCost = *C.first.getValue() / (float)i; + float VectorCost = *C.first.getValue() / (float)i.getFixedValue(); LLVM_DEBUG(dbgs() << "LV: Vector loop of width " << i << " costs: " << (int)VectorCost << ".\n"); if (!C.second && !ForceVectorization) { @@ -5865,7 +5866,7 @@ // If profitable add it to ProfitableVF list. if (VectorCost < ScalarCost) { ProfitableVFs.push_back(VectorizationFactor( - {ElementCount::getFixed(i), (unsigned)VectorCost})); + {i, (unsigned)VectorCost})); } if (VectorCost < Cost) { @@ -5878,16 +5879,16 @@ reportVectorizationFailure("There are conditional stores.", "store that is conditionally executed prevents vectorization", "ConditionalStore", ORE, TheLoop); - Width = 1; + Width = ElementCount::getFixed(1); Cost = ScalarCost; } - LLVM_DEBUG(if (ForceVectorization && Width > 1 && Cost >= ScalarCost) dbgs() + LLVM_DEBUG(if (ForceVectorization && !Width.isScalar() && Cost >= ScalarCost) dbgs() << "LV: Vectorization seems to be not beneficial, " << "but was forced by a user.\n"); LLVM_DEBUG(dbgs() << "LV: Selecting VF: " << Width << ".\n"); - VectorizationFactor Factor = {ElementCount::getFixed(Width), - (unsigned)(Width * Cost)}; + VectorizationFactor Factor = {Width, + (unsigned)(Width.getKnownMinValue() * Cost)}; return Factor; }