Skip to content

Commit ef33a75

Browse files
Turn AddressingModeKind into a bitmask, with All being PreIndexed | PostIndexed
1 parent 3432dd0 commit ef33a75

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 7 additions & 4 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/ADT/BitmaskEnum.h"
2627
#include "llvm/Analysis/IVDescriptors.h"
2728
#include "llvm/IR/FMF.h"
2829
#include "llvm/IR/InstrTypes.h"
@@ -796,11 +797,13 @@ class TargetTransformInfo {
796797
LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC,
797798
TargetLibraryInfo *LibInfo) const;
798799

800+
/// Which addressing mode Loop Strength Reduction will try to generate.
799801
enum AddressingModeKind {
800-
AMK_PreIndexed,
801-
AMK_PostIndexed,
802-
AMK_None,
803-
AMK_All
802+
AMK_None = 0x0, ///< Don't prefer any addressing mode
803+
AMK_PreIndexed = 0x1, ///< Prefer pre-indexed addressing mode
804+
AMK_PostIndexed = 0x2, ///< Prefer post-indexed addressing mode
805+
AMK_All = 0x3, ///< Consider all addressing modes
806+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/AMK_All)
804807
};
805808

806809
/// Return the preferred addressing mode LSR should make efforts to generate.

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,7 @@ void Cost::RateRegister(const Formula &F, const SCEV *Reg,
14021402
// for now LSR only handles innermost loops).
14031403
if (AR->getLoop() != L) {
14041404
// If the AddRec exists, consider it's register free and leave it alone.
1405-
if (isExistingPhi(AR, *SE) && AMK != TTI::AMK_PostIndexed &&
1406-
AMK != TTI::AMK_All)
1405+
if (isExistingPhi(AR, *SE) && !(AMK & TTI::AMK_PostIndexed))
14071406
return;
14081407

14091408
// It is bad to allow LSR for current loop to add induction variables
@@ -1426,11 +1425,10 @@ void Cost::RateRegister(const Formula &F, const SCEV *Reg,
14261425
if (match(AR, m_scev_AffineAddRec(m_SCEV(Start), m_SCEVConstant(Step))))
14271426
// If the step size matches the base offset, we could use pre-indexed
14281427
// addressing.
1429-
if (((AMK == TTI::AMK_PreIndexed || AMK == TTI::AMK_All) &&
1430-
F.BaseOffset.isFixed() &&
1428+
if (((AMK & TTI::AMK_PreIndexed) && F.BaseOffset.isFixed() &&
14311429
Step->getAPInt() == F.BaseOffset.getFixedValue()) ||
1432-
((AMK == TTI::AMK_PostIndexed || AMK == TTI::AMK_All) &&
1433-
!isa<SCEVConstant>(Start) && SE->isLoopInvariant(Start, L)))
1430+
((AMK & TTI::AMK_PostIndexed) && !isa<SCEVConstant>(Start) &&
1431+
SE->isLoopInvariant(Start, L)))
14341432
LoopCost = 0;
14351433
}
14361434
// If the loop counts down to zero and we'll be using a hardware loop then
@@ -4147,8 +4145,7 @@ void LSRInstance::GenerateConstantOffsetsImpl(
41474145
// means that a single pre-indexed access can be generated to become the new
41484146
// base pointer for each iteration of the loop, resulting in no extra add/sub
41494147
// instructions for pointer updating.
4150-
if ((AMK == TTI::AMK_PreIndexed || AMK == TTI::AMK_All) &&
4151-
LU.Kind == LSRUse::Address) {
4148+
if ((AMK & TTI::AMK_PreIndexed) && LU.Kind == LSRUse::Address) {
41524149
const APInt *StepInt;
41534150
if (match(G, m_scev_AffineAddRec(m_SCEV(), m_scev_APInt(StepInt)))) {
41544151
int64_t Step = StepInt->isNegative() ? StepInt->getSExtValue()
@@ -5438,8 +5435,7 @@ void LSRInstance::SolveRecurse(SmallVectorImpl<const Formula *> &Solution,
54385435
// This can sometimes (notably when trying to favour postinc) lead to
54395436
// sub-optimial decisions. There it is best left to the cost modelling to
54405437
// get correct.
5441-
if ((AMK != TTI::AMK_PostIndexed && AMK != TTI::AMK_All) ||
5442-
LU.Kind != LSRUse::Address) {
5438+
if (!(AMK & TTI::AMK_PostIndexed) || LU.Kind != LSRUse::Address) {
54435439
int NumReqRegsToFind = std::min(F.getNumRegs(), ReqRegs.size());
54445440
for (const SCEV *Reg : ReqRegs) {
54455441
if ((F.ScaledReg && F.ScaledReg == Reg) ||

0 commit comments

Comments
 (0)