diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h index 4835c66a7a3bc..2efca0d1d754f 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -23,6 +23,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/Analysis/IVDescriptors.h" #include "llvm/IR/FMF.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/PassManager.h" @@ -1777,8 +1778,9 @@ class TargetTransformInfo { /// vectorization, false - otherwise. bool preferAlternateOpcodeVectorization() const; - /// \returns True if the target prefers reductions in loop. - bool preferInLoopReduction(unsigned Opcode, Type *Ty) const; + /// \returns True if the target prefers reductions of \p Kind to be performed + /// in the loop. + bool preferInLoopReduction(RecurKind Kind, Type *Ty) const; /// \returns True if the target prefers reductions select kept in the loop /// when tail folding. i.e. @@ -2330,7 +2332,7 @@ class TargetTransformInfo::Concept { unsigned ChainSizeInBytes, VectorType *VecTy) const = 0; virtual bool preferFixedOverScalableIfEqualCost() const = 0; - virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty) const = 0; + virtual bool preferInLoopReduction(RecurKind Kind, Type *Ty) const = 0; virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty) const = 0; virtual bool preferAlternateOpcodeVectorization() const = 0; @@ -3143,8 +3145,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept { bool preferFixedOverScalableIfEqualCost() const override { return Impl.preferFixedOverScalableIfEqualCost(); } - bool preferInLoopReduction(unsigned Opcode, Type *Ty) const override { - return Impl.preferInLoopReduction(Opcode, Ty); + bool preferInLoopReduction(RecurKind Kind, Type *Ty) const override { + return Impl.preferInLoopReduction(Kind, Ty); } bool preferAlternateOpcodeVectorization() const override { return Impl.preferAlternateOpcodeVectorization(); diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index 261d5eacc91b0..3fe0a9101fdee 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -1010,7 +1010,7 @@ class TargetTransformInfoImplBase { bool preferFixedOverScalableIfEqualCost() const { return false; } - bool preferInLoopReduction(unsigned Opcode, Type *Ty) const { return false; } + bool preferInLoopReduction(RecurKind Kind, Type *Ty) const { return false; } bool preferAlternateOpcodeVectorization() const { return true; } bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty) const { diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index e3212135e9b19..4fea4e5711f5a 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -1380,9 +1380,9 @@ bool TargetTransformInfo::preferFixedOverScalableIfEqualCost() const { return TTIImpl->preferFixedOverScalableIfEqualCost(); } -bool TargetTransformInfo::preferInLoopReduction(unsigned Opcode, +bool TargetTransformInfo::preferInLoopReduction(RecurKind Kind, Type *Ty) const { - return TTIImpl->preferInLoopReduction(Opcode, Ty); + return TTIImpl->preferInLoopReduction(Kind, Ty); } bool TargetTransformInfo::preferAlternateOpcodeVectorization() const { diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 77be41b78bc7f..417af74f712e7 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -12,7 +12,6 @@ #include "MCTargetDesc/AArch64AddressingModes.h" #include "Utils/AArch64SMEAttributes.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/Analysis/IVDescriptors.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/CodeGen/BasicTTIImpl.h" diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 1b134bbe5ff6a..2f9c262511ae4 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -2693,13 +2693,13 @@ void ARMTTIImpl::getPeelingPreferences(Loop *L, ScalarEvolution &SE, BaseT::getPeelingPreferences(L, SE, PP); } -bool ARMTTIImpl::preferInLoopReduction(unsigned Opcode, Type *Ty) const { +bool ARMTTIImpl::preferInLoopReduction(RecurKind Kind, Type *Ty) const { if (!ST->hasMVEIntegerOps()) return false; unsigned ScalarBits = Ty->getScalarSizeInBits(); - switch (Opcode) { - case Instruction::Add: + switch (Kind) { + case RecurKind::Add: return ScalarBits <= 64; default: return false; diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h index ca5129c997fb0..2b144f1628038 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h @@ -224,7 +224,7 @@ class ARMTTIImpl : public BasicTTIImplBase { ArrayRef Args = {}, const Instruction *CxtI = nullptr); - bool preferInLoopReduction(unsigned Opcode, Type *Ty) const; + bool preferInLoopReduction(RecurKind Kind, Type *Ty) const; bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty) const; diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h index 1c5524748b605..c61dd1507f168 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -18,7 +18,6 @@ #include "RISCVSubtarget.h" #include "RISCVTargetMachine.h" -#include "llvm/Analysis/IVDescriptors.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/CodeGen/BasicTTIImpl.h" #include "llvm/IR/Function.h" diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index cf7804e19e722..5df1061691a67 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4853,7 +4853,7 @@ void LoopVectorizationCostModel::collectElementTypesForWidening() { const RecurrenceDescriptor &RdxDesc = Legal->getReductionVars().find(PN)->second; if (PreferInLoopReductions || useOrderedReductions(RdxDesc) || - TTI.preferInLoopReduction(RdxDesc.getOpcode(), + TTI.preferInLoopReduction(RdxDesc.getRecurrenceKind(), RdxDesc.getRecurrenceType())) continue; T = RdxDesc.getRecurrenceType(); @@ -7020,9 +7020,9 @@ void LoopVectorizationCostModel::collectInLoopReductions() { // If the target would prefer this reduction to happen "in-loop", then we // want to record it as such. - unsigned Opcode = RdxDesc.getOpcode(); + RecurKind Kind = RdxDesc.getRecurrenceKind(); if (!PreferInLoopReductions && !useOrderedReductions(RdxDesc) && - !TTI.preferInLoopReduction(Opcode, Phi->getType())) + !TTI.preferInLoopReduction(Kind, Phi->getType())) continue; // Check that we can correctly put the reductions into the loop, by