30
30
#include " llvm/Analysis/OptimizationRemarkEmitter.h"
31
31
#include " llvm/Analysis/ScalarEvolution.h"
32
32
#include " llvm/Analysis/ScalarEvolutionExpressions.h"
33
+ #include " llvm/Analysis/ScalarEvolutionPatternMatch.h"
33
34
#include " llvm/Analysis/TargetLibraryInfo.h"
34
35
#include " llvm/Analysis/TargetTransformInfo.h"
35
36
#include " llvm/Analysis/ValueTracking.h"
65
66
#include < vector>
66
67
67
68
using namespace llvm ;
69
+ using namespace llvm ::SCEVPatternMatch;
68
70
69
71
#define DEBUG_TYPE " loop-accesses"
70
72
@@ -811,8 +813,8 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
811
813
const SCEV *Step = AR->getStepRecurrence (*PSE.getSE ());
812
814
813
815
// Calculate the pointer stride and check if it is constant.
814
- const SCEVConstant *C = dyn_cast<SCEVConstant>(Step) ;
815
- if (!C ) {
816
+ const APInt *APStepVal ;
817
+ if (!match (Step, m_SCEVConstant (APStepVal)) ) {
816
818
LLVM_DEBUG ({
817
819
dbgs () << " LAA: Bad stride - Not a constant strided " ;
818
820
if (Ptr)
@@ -825,13 +827,12 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
825
827
const auto &DL = Lp->getHeader ()->getDataLayout ();
826
828
TypeSize AllocSize = DL.getTypeAllocSize (AccessTy);
827
829
int64_t Size = AllocSize.getFixedValue ();
828
- const APInt &APStepVal = C->getAPInt ();
829
830
830
831
// Huge step value - give up.
831
- if (APStepVal. getBitWidth () > 64 )
832
+ if (APStepVal-> getBitWidth () > 64 )
832
833
return std::nullopt;
833
834
834
- int64_t StepVal = APStepVal. getSExtValue ();
835
+ int64_t StepVal = APStepVal-> getSExtValue ();
835
836
836
837
// Strided access.
837
838
int64_t Stride = StepVal / Size;
@@ -2061,11 +2062,10 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2061
2062
DL, SE, *(PSE.getSymbolicMaxBackedgeTakenCount ()), *Dist, MaxStride))
2062
2063
return Dependence::NoDep;
2063
2064
2064
- const SCEVConstant *ConstDist = dyn_cast<SCEVConstant>(Dist);
2065
-
2066
2065
// Attempt to prove strided accesses independent.
2067
- if (ConstDist) {
2068
- uint64_t Distance = ConstDist->getAPInt ().abs ().getZExtValue ();
2066
+ const APInt *ConstDist = nullptr ;
2067
+ if (match (Dist, m_SCEVConstant (ConstDist))) {
2068
+ uint64_t Distance = ConstDist->abs ().getZExtValue ();
2069
2069
2070
2070
// If the distance between accesses and their strides are known constants,
2071
2071
// check whether the accesses interlace each other.
@@ -2111,9 +2111,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2111
2111
FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck;
2112
2112
return Dependence::Unknown;
2113
2113
}
2114
- if (!HasSameSize ||
2115
- couldPreventStoreLoadForward (
2116
- ConstDist->getAPInt ().abs ().getZExtValue (), TypeByteSize)) {
2114
+ if (!HasSameSize || couldPreventStoreLoadForward (
2115
+ ConstDist->abs ().getZExtValue (), TypeByteSize)) {
2117
2116
LLVM_DEBUG (
2118
2117
dbgs () << " LAA: Forward but may prevent st->ld forwarding\n " );
2119
2118
return Dependence::ForwardButPreventsForwarding;
@@ -2864,20 +2863,8 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
2864
2863
2865
2864
// Strip off the size of access multiplication if we are still analyzing the
2866
2865
// pointer.
2867
- if (OrigPtr == Ptr) {
2868
- if (auto *M = dyn_cast<SCEVMulExpr>(V)) {
2869
- auto *StepConst = dyn_cast<SCEVConstant>(M->getOperand (0 ));
2870
- if (!StepConst)
2871
- return nullptr ;
2872
-
2873
- auto StepVal = StepConst->getAPInt ().trySExtValue ();
2874
- // Bail out on a non-unit pointer access size.
2875
- if (!StepVal || StepVal != 1 )
2876
- return nullptr ;
2877
-
2878
- V = M->getOperand (1 );
2879
- }
2880
- }
2866
+ if (OrigPtr == Ptr)
2867
+ match (V, m_scev_Mul (m_SCEVConstant (1 ), m_SCEV (V)));
2881
2868
2882
2869
// Note that the restriction after this loop invariant check are only
2883
2870
// profitability restrictions.
0 commit comments