From e00cdcda53b61b1bc9583ad5e6282dac2f7154c6 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Fri, 21 Nov 2025 10:27:16 +0000 Subject: [PATCH 1/2] [IVDesc] Make getCastInsts return an ArrayRef (NFC) To make it clear that the return value is immutable. --- llvm/include/llvm/Analysis/IVDescriptors.h | 4 +--- llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp | 2 +- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 3 +-- llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h index 654a5f10cea96..724ab8364249d 100644 --- a/llvm/include/llvm/Analysis/IVDescriptors.h +++ b/llvm/include/llvm/Analysis/IVDescriptors.h @@ -454,9 +454,7 @@ class InductionDescriptor { /// Returns a reference to the type cast instructions in the induction /// update chain, that are redundant when guarded with a runtime /// SCEV overflow check. - const SmallVectorImpl &getCastInsts() const { - return RedundantCasts; - } + ArrayRef getCastInsts() const { return RedundantCasts; } private: /// Private constructor - used by \c isInductionPHI. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp index 86e742ca5fec1..ba21bbbe112e6 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp @@ -684,7 +684,7 @@ void LoopVectorizationLegality::addInductionPhi( // in the vectorized loop body, record them here. All casts could be recorded // here for ignoring, but suffices to record only the first (as it is the // only one that may bw used outside the cast sequence). - const SmallVectorImpl &Casts = ID.getCastInsts(); + ArrayRef Casts = ID.getCastInsts(); if (!Casts.empty()) InductionCastsToIgnore.insert(*Casts.begin()); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5b8725178521e..5ae90aa76c27d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6575,8 +6575,7 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // detection. for (const auto &Induction : Legal->getInductionVars()) { const InductionDescriptor &IndDes = Induction.second; - const SmallVectorImpl &Casts = IndDes.getCastInsts(); - VecValuesToIgnore.insert_range(Casts); + VecValuesToIgnore.insert_range(IndDes.getCastInsts()); } } diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index a6a03c0d805fd..6cffdcce4013d 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -512,7 +512,7 @@ static void removeRedundantInductionCasts(VPlan &Plan) { // replace it with the original IV. Note that only the final cast is // expected to have users outside the cast-chain and the dead casts left // over will be cleaned up later. - auto &Casts = IV->getInductionDescriptor().getCastInsts(); + ArrayRef Casts = IV->getInductionDescriptor().getCastInsts(); VPValue *FindMyCast = IV; for (Instruction *IRCast : reverse(Casts)) { VPSingleDefRecipe *FoundUserCast = nullptr; From 656efc1f26126abf71fd7764bafcd5690a53c36c Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Mon, 24 Nov 2025 08:26:44 +0000 Subject: [PATCH 2/2] [IVDesc] Update hdr comment --- llvm/include/llvm/Analysis/IVDescriptors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h index 724ab8364249d..2c8484fde5b16 100644 --- a/llvm/include/llvm/Analysis/IVDescriptors.h +++ b/llvm/include/llvm/Analysis/IVDescriptors.h @@ -451,7 +451,7 @@ class InductionDescriptor { : Instruction::BinaryOpsEnd; } - /// Returns a reference to the type cast instructions in the induction + /// Returns an ArrayRef to the type cast instructions in the induction /// update chain, that are redundant when guarded with a runtime /// SCEV overflow check. ArrayRef getCastInsts() const { return RedundantCasts; }