[llvm] [Vectorize] Fix warnings (PR #105777)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 20:54:35 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/105777

This patch fixes warnings of the form:

  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:9300:23: error: loop
  variable '[E, Idx]' creates a copy from type 'const value_type' (aka
  'const std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry *,
  unsigned int>') [-Werror,-Wrange-loop-construct]

I tried to fix this with "const auto &[...]", but that triggered an
assert on some host compiler:

https://lab.llvm.org/buildbot/#/builders/51/builds/2836

This patch removes const instead.


>From 21bcbf1ea697cd7d073e6f08b48e4cae8cd49c86 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 22 Aug 2024 20:47:12 -0700
Subject: [PATCH] [Vectorize] Fix warnings

This patch fixes warnings of the form:

  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:9300:23: error: loop
  variable '[E, Idx]' creates a copy from type 'const value_type' (aka
  'const std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry *,
  unsigned int>') [-Werror,-Wrange-loop-construct]

I tried to fix this with "const auto &[...]", but that triggered an
assert on some host compiler:

https://lab.llvm.org/buildbot/#/builders/51/builds/2836

This patch removes const instead.
---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index afaef6f9da9872..d00c9f39b70aa3 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -9297,7 +9297,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
       for (unsigned Idx = 0, Sz = CommonMask.size(); Idx < Sz; ++Idx)
         if (CommonMask[Idx] != PoisonMaskElem)
           CommonMask[Idx] = Idx;
-      for (const auto [E, Idx] : SubVectors) {
+      for (auto [E, Idx] : SubVectors) {
         Cost += ::getShuffleCost(
             TTI, TTI::SK_InsertSubvector,
             FixedVectorType::get(ScalarTy, CommonMask.size()), std::nullopt,
@@ -12455,7 +12455,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
       for (unsigned Idx = 0, Sz = CommonMask.size(); Idx < Sz; ++Idx)
         if (CommonMask[Idx] != PoisonMaskElem)
           CommonMask[Idx] = Idx;
-      for (const auto [E, Idx] : SubVectors) {
+      for (auto [E, Idx] : SubVectors) {
         Vec = Builder.CreateInsertVector(
             Vec->getType(), Vec, E->VectorizedValue, Builder.getInt64(Idx));
         if (!CommonMask.empty()) {
@@ -12636,7 +12636,7 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy,
                                        E->ReuseShuffleIndices.end());
   SmallVector<Value *> GatheredScalars(E->Scalars.begin(), E->Scalars.end());
   // Clear values, to be replaced by insertvector instructions.
-  for (const auto [EIdx, Idx] : E->CombinedEntriesWithIndices)
+  for (auto [EIdx, Idx] : E->CombinedEntriesWithIndices)
     for_each(MutableArrayRef(GatheredScalars)
                  .slice(Idx, VectorizableTree[EIdx]->getVectorFactor()),
              [&](Value *&V) { V = PoisonValue::get(V->getType()); });
@@ -13073,7 +13073,7 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy,
 }
 
 Value *BoUpSLP::createBuildVector(const TreeEntry *E, Type *ScalarTy) {
-  for (const auto [EIdx, _] : E->CombinedEntriesWithIndices)
+  for (auto [EIdx, _] : E->CombinedEntriesWithIndices)
     (void)vectorizeTree(VectorizableTree[EIdx].get(), /*PostponedPHIs=*/false);
   return processBuildVector<ShuffleInstructionBuilder, Value *>(E, ScalarTy,
                                                                 Builder, *this);



More information about the llvm-commits mailing list