Skip to content

Commit 409df9f

Browse files
authored
[TTI][LV] Change the prototype of preferInLoopReduction. nfc (#132698)
This patch changes the preferInLoopReduction function to take a RecurKind instead of an unsigned Opcode. This makes it possible to distinguish non-arithmetic reductions such as min/max, AnyOf, and FindLastIV, and also helps unify IAnyOf with FAnyOf and IFindLastIV with FFindLastIV. Related patch #118393 #131830
1 parent 2c10723 commit 409df9f

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "llvm/ADT/APInt.h"
2525
#include "llvm/ADT/ArrayRef.h"
26+
#include "llvm/Analysis/IVDescriptors.h"
2627
#include "llvm/IR/FMF.h"
2728
#include "llvm/IR/InstrTypes.h"
2829
#include "llvm/IR/PassManager.h"
@@ -1777,8 +1778,9 @@ class TargetTransformInfo {
17771778
/// vectorization, false - otherwise.
17781779
bool preferAlternateOpcodeVectorization() const;
17791780

1780-
/// \returns True if the target prefers reductions in loop.
1781-
bool preferInLoopReduction(unsigned Opcode, Type *Ty) const;
1781+
/// \returns True if the target prefers reductions of \p Kind to be performed
1782+
/// in the loop.
1783+
bool preferInLoopReduction(RecurKind Kind, Type *Ty) const;
17821784

17831785
/// \returns True if the target prefers reductions select kept in the loop
17841786
/// when tail folding. i.e.
@@ -2330,7 +2332,7 @@ class TargetTransformInfo::Concept {
23302332
unsigned ChainSizeInBytes,
23312333
VectorType *VecTy) const = 0;
23322334
virtual bool preferFixedOverScalableIfEqualCost() const = 0;
2333-
virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty) const = 0;
2335+
virtual bool preferInLoopReduction(RecurKind Kind, Type *Ty) const = 0;
23342336
virtual bool preferPredicatedReductionSelect(unsigned Opcode,
23352337
Type *Ty) const = 0;
23362338
virtual bool preferAlternateOpcodeVectorization() const = 0;
@@ -3143,8 +3145,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
31433145
bool preferFixedOverScalableIfEqualCost() const override {
31443146
return Impl.preferFixedOverScalableIfEqualCost();
31453147
}
3146-
bool preferInLoopReduction(unsigned Opcode, Type *Ty) const override {
3147-
return Impl.preferInLoopReduction(Opcode, Ty);
3148+
bool preferInLoopReduction(RecurKind Kind, Type *Ty) const override {
3149+
return Impl.preferInLoopReduction(Kind, Ty);
31483150
}
31493151
bool preferAlternateOpcodeVectorization() const override {
31503152
return Impl.preferAlternateOpcodeVectorization();

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ class TargetTransformInfoImplBase {
10101010

10111011
bool preferFixedOverScalableIfEqualCost() const { return false; }
10121012

1013-
bool preferInLoopReduction(unsigned Opcode, Type *Ty) const { return false; }
1013+
bool preferInLoopReduction(RecurKind Kind, Type *Ty) const { return false; }
10141014
bool preferAlternateOpcodeVectorization() const { return true; }
10151015

10161016
bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty) const {

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,9 @@ bool TargetTransformInfo::preferFixedOverScalableIfEqualCost() const {
13801380
return TTIImpl->preferFixedOverScalableIfEqualCost();
13811381
}
13821382

1383-
bool TargetTransformInfo::preferInLoopReduction(unsigned Opcode,
1383+
bool TargetTransformInfo::preferInLoopReduction(RecurKind Kind,
13841384
Type *Ty) const {
1385-
return TTIImpl->preferInLoopReduction(Opcode, Ty);
1385+
return TTIImpl->preferInLoopReduction(Kind, Ty);
13861386
}
13871387

13881388
bool TargetTransformInfo::preferAlternateOpcodeVectorization() const {

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "MCTargetDesc/AArch64AddressingModes.h"
1313
#include "Utils/AArch64SMEAttributes.h"
1414
#include "llvm/ADT/DenseMap.h"
15-
#include "llvm/Analysis/IVDescriptors.h"
1615
#include "llvm/Analysis/LoopInfo.h"
1716
#include "llvm/Analysis/TargetTransformInfo.h"
1817
#include "llvm/CodeGen/BasicTTIImpl.h"

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,13 +2693,13 @@ void ARMTTIImpl::getPeelingPreferences(Loop *L, ScalarEvolution &SE,
26932693
BaseT::getPeelingPreferences(L, SE, PP);
26942694
}
26952695

2696-
bool ARMTTIImpl::preferInLoopReduction(unsigned Opcode, Type *Ty) const {
2696+
bool ARMTTIImpl::preferInLoopReduction(RecurKind Kind, Type *Ty) const {
26972697
if (!ST->hasMVEIntegerOps())
26982698
return false;
26992699

27002700
unsigned ScalarBits = Ty->getScalarSizeInBits();
2701-
switch (Opcode) {
2702-
case Instruction::Add:
2701+
switch (Kind) {
2702+
case RecurKind::Add:
27032703
return ScalarBits <= 64;
27042704
default:
27052705
return false;

llvm/lib/Target/ARM/ARMTargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
224224
ArrayRef<const Value *> Args = {},
225225
const Instruction *CxtI = nullptr);
226226

227-
bool preferInLoopReduction(unsigned Opcode, Type *Ty) const;
227+
bool preferInLoopReduction(RecurKind Kind, Type *Ty) const;
228228

229229
bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty) const;
230230

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "RISCVSubtarget.h"
2020
#include "RISCVTargetMachine.h"
21-
#include "llvm/Analysis/IVDescriptors.h"
2221
#include "llvm/Analysis/TargetTransformInfo.h"
2322
#include "llvm/CodeGen/BasicTTIImpl.h"
2423
#include "llvm/IR/Function.h"

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,7 +4853,7 @@ void LoopVectorizationCostModel::collectElementTypesForWidening() {
48534853
const RecurrenceDescriptor &RdxDesc =
48544854
Legal->getReductionVars().find(PN)->second;
48554855
if (PreferInLoopReductions || useOrderedReductions(RdxDesc) ||
4856-
TTI.preferInLoopReduction(RdxDesc.getOpcode(),
4856+
TTI.preferInLoopReduction(RdxDesc.getRecurrenceKind(),
48574857
RdxDesc.getRecurrenceType()))
48584858
continue;
48594859
T = RdxDesc.getRecurrenceType();
@@ -7020,9 +7020,9 @@ void LoopVectorizationCostModel::collectInLoopReductions() {
70207020

70217021
// If the target would prefer this reduction to happen "in-loop", then we
70227022
// want to record it as such.
7023-
unsigned Opcode = RdxDesc.getOpcode();
7023+
RecurKind Kind = RdxDesc.getRecurrenceKind();
70247024
if (!PreferInLoopReductions && !useOrderedReductions(RdxDesc) &&
7025-
!TTI.preferInLoopReduction(Opcode, Phi->getType()))
7025+
!TTI.preferInLoopReduction(Kind, Phi->getType()))
70267026
continue;
70277027

70287028
// Check that we can correctly put the reductions into the loop, by

0 commit comments

Comments
 (0)