Skip to content

Commit 60e5b86

Browse files
committed
[VPlan] Support extends and truncs in getSCEVExprForVPValue. (NFCI)
Handle extends and truncates in getSCEVExprForVPValue. This enables computing SCEVs in more cases in the VPlan-based cost-model, but should compute the matching costs in all cases.
1 parent 295a01f commit 60e5b86

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "VPlanUtils.h"
10+
#include "VPlanAnalysis.h"
1011
#include "VPlanCFG.h"
1112
#include "VPlanDominatorTree.h"
1213
#include "VPlanPatternMatch.h"
@@ -116,6 +117,27 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
116117
return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<const SCEV *> Ops) {
117118
return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
118119
});
120+
if (match(V, m_Trunc(m_VPValue(LHSVal)))) {
121+
const VPlan *Plan = V->getDefiningRecipe()->getParent()->getPlan();
122+
Type *DestTy = VPTypeAnalysis(*Plan).inferScalarType(V);
123+
return CreateSCEV({LHSVal}, [&](ArrayRef<const SCEV *> Ops) {
124+
return SE.getTruncateExpr(Ops[0], DestTy);
125+
});
126+
}
127+
if (match(V, m_ZExt(m_VPValue(LHSVal)))) {
128+
const VPlan *Plan = V->getDefiningRecipe()->getParent()->getPlan();
129+
Type *DestTy = VPTypeAnalysis(*Plan).inferScalarType(V);
130+
return CreateSCEV({LHSVal}, [&](ArrayRef<const SCEV *> Ops) {
131+
return SE.getZeroExtendExpr(Ops[0], DestTy);
132+
});
133+
}
134+
if (match(V, m_SExt(m_VPValue(LHSVal)))) {
135+
const VPlan *Plan = V->getDefiningRecipe()->getParent()->getPlan();
136+
Type *DestTy = VPTypeAnalysis(*Plan).inferScalarType(V);
137+
return CreateSCEV({LHSVal}, [&](ArrayRef<const SCEV *> Ops) {
138+
return SE.getSignExtendExpr(Ops[0], DestTy);
139+
});
140+
}
119141

120142
// TODO: Support constructing SCEVs for more recipes as needed.
121143
const VPRecipeBase *DefR = V->getDefiningRecipe();

0 commit comments

Comments
 (0)