@@ -923,10 +923,11 @@ static const SCEV *getExactSDiv(const SCEV *LHS, const SCEV *RHS,
923
923
// / If S involves the addition of a constant integer value, return that integer
924
924
// / value, and mutate S to point to a new SCEV with that value excluded.
925
925
static Immediate ExtractImmediate (const SCEV *&S, ScalarEvolution &SE) {
926
- if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) {
927
- if (C->getAPInt ().getSignificantBits () <= 64 ) {
928
- S = SE.getConstant (C->getType (), 0 );
929
- return Immediate::getFixed (C->getValue ()->getSExtValue ());
926
+ const APInt *C;
927
+ if (match (S, m_scev_APInt (C))) {
928
+ if (C->getSignificantBits () <= 64 ) {
929
+ S = SE.getConstant (S->getType (), 0 );
930
+ return Immediate::getFixed (C->getSExtValue ());
930
931
}
931
932
} else if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
932
933
SmallVector<const SCEV *, 8 > NewOps (Add->operands ());
@@ -942,14 +943,10 @@ static Immediate ExtractImmediate(const SCEV *&S, ScalarEvolution &SE) {
942
943
// FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
943
944
SCEV::FlagAnyWrap);
944
945
return Result;
945
- } else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
946
- if (EnableVScaleImmediates && M->getNumOperands () == 2 ) {
947
- if (const SCEVConstant *C = dyn_cast<SCEVConstant>(M->getOperand (0 )))
948
- if (isa<SCEVVScale>(M->getOperand (1 ))) {
949
- S = SE.getConstant (M->getType (), 0 );
950
- return Immediate::getScalable (C->getValue ()->getSExtValue ());
951
- }
952
- }
946
+ } else if (EnableVScaleImmediates &&
947
+ match (S, m_scev_Mul (m_scev_APInt (C), m_SCEVVScale ()))) {
948
+ S = SE.getConstant (S->getType (), 0 );
949
+ return Immediate::getScalable (C->getSExtValue ());
953
950
}
954
951
return Immediate::getZero ();
955
952
}
@@ -1133,23 +1130,22 @@ static bool isHighCostExpansion(const SCEV *S,
1133
1130
return false ;
1134
1131
}
1135
1132
1136
- if (const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(S)) {
1137
- if (Mul->getNumOperands () == 2 ) {
1138
- // Multiplication by a constant is ok
1139
- if (isa<SCEVConstant>(Mul->getOperand (0 )))
1140
- return isHighCostExpansion (Mul->getOperand (1 ), Processed, SE);
1141
-
1142
- // If we have the value of one operand, check if an existing
1143
- // multiplication already generates this expression.
1144
- if (const SCEVUnknown *U = dyn_cast<SCEVUnknown>(Mul->getOperand (1 ))) {
1145
- Value *UVal = U->getValue ();
1146
- for (User *UR : UVal->users ()) {
1147
- // If U is a constant, it may be used by a ConstantExpr.
1148
- Instruction *UI = dyn_cast<Instruction>(UR);
1149
- if (UI && UI->getOpcode () == Instruction::Mul &&
1150
- SE.isSCEVable (UI->getType ())) {
1151
- return SE.getSCEV (UI) == Mul;
1152
- }
1133
+ const SCEV *Op0, *Op1;
1134
+ if (match (S, m_scev_Mul (m_SCEV (Op0), m_SCEV (Op1)))) {
1135
+ // Multiplication by a constant is ok
1136
+ if (isa<SCEVConstant>(Op0))
1137
+ return isHighCostExpansion (Op1, Processed, SE);
1138
+
1139
+ // If we have the value of one operand, check if an existing
1140
+ // multiplication already generates this expression.
1141
+ if (const auto *U = dyn_cast<SCEVUnknown>(Op1)) {
1142
+ Value *UVal = U->getValue ();
1143
+ for (User *UR : UVal->users ()) {
1144
+ // If U is a constant, it may be used by a ConstantExpr.
1145
+ Instruction *UI = dyn_cast<Instruction>(UR);
1146
+ if (UI && UI->getOpcode () == Instruction::Mul &&
1147
+ SE.isSCEVable (UI->getType ())) {
1148
+ return SE.getSCEV (UI) == S;
1153
1149
}
1154
1150
}
1155
1151
}
@@ -3333,14 +3329,11 @@ static bool canFoldIVIncExpr(const SCEV *IncExpr, Instruction *UserInst,
3333
3329
IncOffset = Immediate::getFixed (IncConst->getValue ()->getSExtValue ());
3334
3330
} else {
3335
3331
// Look for mul(vscale, constant), to detect a scalable offset.
3336
- auto *IncVScale = dyn_cast<SCEVMulExpr>(IncExpr) ;
3337
- if (!IncVScale || IncVScale-> getNumOperands () != 2 ||
3338
- !isa<SCEVVScale>(IncVScale-> getOperand ( 1 )) )
3332
+ const APInt *C ;
3333
+ if (!match (IncExpr, m_scev_Mul ( m_scev_APInt (C), m_SCEVVScale ())) ||
3334
+ C-> getSignificantBits () > 64 )
3339
3335
return false ;
3340
- auto *Scale = dyn_cast<SCEVConstant>(IncVScale->getOperand (0 ));
3341
- if (!Scale || Scale->getType ()->getScalarSizeInBits () > 64 )
3342
- return false ;
3343
- IncOffset = Immediate::getScalable (Scale->getValue ()->getSExtValue ());
3336
+ IncOffset = Immediate::getScalable (C->getSExtValue ());
3344
3337
}
3345
3338
3346
3339
if (!isAddressUse (TTI, UserInst, Operand))
@@ -3818,6 +3811,8 @@ static const SCEV *CollectSubexprs(const SCEV *S, const SCEVConstant *C,
3818
3811
return nullptr ;
3819
3812
}
3820
3813
const SCEV *Start, *Step;
3814
+ const SCEVConstant *Op0;
3815
+ const SCEV *Op1;
3821
3816
if (match (S, m_scev_AffineAddRec (m_SCEV (Start), m_SCEV (Step)))) {
3822
3817
// Split a non-zero base out of an addrec.
3823
3818
if (Start->isZero ())
@@ -3839,19 +3834,13 @@ static const SCEV *CollectSubexprs(const SCEV *S, const SCEVConstant *C,
3839
3834
// FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
3840
3835
SCEV::FlagAnyWrap);
3841
3836
}
3842
- } else if (const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(S )) {
3837
+ } else if (match (S, m_scev_Mul ( m_SCEVConstant (Op0), m_SCEV (Op1)) )) {
3843
3838
// Break (C * (a + b + c)) into C*a + C*b + C*c.
3844
- if (Mul->getNumOperands () != 2 )
3845
- return S;
3846
- if (const SCEVConstant *Op0 =
3847
- dyn_cast<SCEVConstant>(Mul->getOperand (0 ))) {
3848
- C = C ? cast<SCEVConstant>(SE.getMulExpr (C, Op0)) : Op0;
3849
- const SCEV *Remainder =
3850
- CollectSubexprs (Mul->getOperand (1 ), C, Ops, L, SE, Depth+1 );
3851
- if (Remainder)
3852
- Ops.push_back (SE.getMulExpr (C, Remainder));
3853
- return nullptr ;
3854
- }
3839
+ C = C ? cast<SCEVConstant>(SE.getMulExpr (C, Op0)) : Op0;
3840
+ const SCEV *Remainder = CollectSubexprs (Op1, C, Ops, L, SE, Depth + 1 );
3841
+ if (Remainder)
3842
+ Ops.push_back (SE.getMulExpr (C, Remainder));
3843
+ return nullptr ;
3855
3844
}
3856
3845
return S;
3857
3846
}
0 commit comments