Skip to content

[TTI][LV] Change the prototype of preferInLoopReduction. nfc #132698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
ArrayRef<const Value *> 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;

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down