-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[VPlan] Add opcode to create step for wide inductions. #119284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
a55fe62
8c359c7
6b671a7
9e94c1e
7e2a729
2efecd5
be8206e
db536f9
43be877
669f5ad
b9f7d12
ad35c37
84af6da
1702651
169e599
de0133d
1027c7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
lukel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1019,6 +1019,16 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) { | |
TypeInfo.inferScalarType(R.getOperand(1)) == | ||
TypeInfo.inferScalarType(R.getVPSingleValue())) | ||
return R.getVPSingleValue()->replaceAllUsesWith(R.getOperand(1)); | ||
|
||
if (match(&R, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue(X), | ||
m_SpecificInt(1)))) { | ||
Type *WideStepTy = TypeInfo.inferScalarType(R.getVPSingleValue()); | ||
if (TypeInfo.inferScalarType(X) != WideStepTy) { | ||
X = new VPWidenCastRecipe(Instruction::Trunc, X, WideStepTy); | ||
X->getDefiningRecipe()->insertBefore(&R); | ||
} | ||
R.getVPSingleValue()->replaceAllUsesWith(X); | ||
} | ||
} | ||
|
||
void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) { | ||
|
@@ -2367,21 +2377,62 @@ void VPlanTransforms::createInterleaveGroups( | |
} | ||
} | ||
|
||
void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan) { | ||
void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan, | ||
VPTypeAnalysis &TypeInfo) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just pass in the canonical IV and construct the TypeInfo in convertToConcreteRecipes, since I think it'll be invalid once convertToConcreteRecipes returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, I think it would be clearer to pass the type analysis interface wise, but undone for now, until your patch lands adding support for invalidating entries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I can break that off into a separate patch if you'd like |
||
using namespace llvm::VPlanPatternMatch; | ||
|
||
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>( | ||
vp_depth_first_deep(Plan.getEntry()))) { | ||
for (VPRecipeBase &R : make_early_inc_range(VPBB->phis())) { | ||
if (!isa<VPCanonicalIVPHIRecipe, VPEVLBasedIVPHIRecipe>(&R)) | ||
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) { | ||
if (isa<VPCanonicalIVPHIRecipe, VPEVLBasedIVPHIRecipe>(&R)) { | ||
auto *PhiR = cast<VPHeaderPHIRecipe>(&R); | ||
StringRef Name = | ||
isa<VPCanonicalIVPHIRecipe>(PhiR) ? "index" : "evl.based.iv"; | ||
auto *ScalarR = new VPInstruction( | ||
Instruction::PHI, {PhiR->getStartValue(), PhiR->getBackedgeValue()}, | ||
PhiR->getDebugLoc(), Name); | ||
ScalarR->insertBefore(PhiR); | ||
PhiR->replaceAllUsesWith(ScalarR); | ||
PhiR->eraseFromParent(); | ||
continue; | ||
} | ||
|
||
VPValue *VectorStep; | ||
VPValue *ScalarStep; | ||
if (!match(&R, m_VPInstruction<VPInstruction::WideIVStep>( | ||
m_VPValue(VectorStep), m_VPValue(ScalarStep)))) | ||
continue; | ||
auto *PhiR = cast<VPHeaderPHIRecipe>(&R); | ||
StringRef Name = | ||
isa<VPCanonicalIVPHIRecipe>(PhiR) ? "index" : "evl.based.iv"; | ||
auto *ScalarR = new VPInstruction( | ||
Instruction::PHI, {PhiR->getStartValue(), PhiR->getBackedgeValue()}, | ||
PhiR->getDebugLoc(), Name); | ||
ScalarR->insertBefore(PhiR); | ||
PhiR->replaceAllUsesWith(ScalarR); | ||
PhiR->eraseFromParent(); | ||
auto *VPI = cast<VPInstruction>(&R); | ||
VPBuilder Builder(VPI->getParent(), VPI->getIterator()); | ||
lukel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Type *IVTy = TypeInfo.inferScalarType(VPI); | ||
if (TypeInfo.inferScalarType(VectorStep) != IVTy) { | ||
Instruction::CastOps CastOp = IVTy->isFloatingPointTy() | ||
? Instruction::UIToFP | ||
: Instruction::Trunc; | ||
VectorStep = Builder.createWidenCast(CastOp, VectorStep, IVTy); | ||
} | ||
|
||
auto *ConstStep = | ||
ScalarStep->isLiveIn() | ||
? dyn_cast<ConstantInt>(ScalarStep->getLiveInIRValue()) | ||
: nullptr; | ||
assert(!ConstStep || ConstStep->getValue() != 1); | ||
if (TypeInfo.inferScalarType(ScalarStep) != IVTy) { | ||
ScalarStep = | ||
Builder.createWidenCast(Instruction::Trunc, ScalarStep, IVTy); | ||
} | ||
|
||
std::optional<FastMathFlags> FMFs; | ||
if (IVTy->isFloatingPointTy()) | ||
lukel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FMFs = VPI->getFastMathFlags(); | ||
|
||
unsigned MulOpc = | ||
IVTy->isFloatingPointTy() ? Instruction::FMul : Instruction::Mul; | ||
VPInstruction *Mul = Builder.createNaryOp( | ||
MulOpc, {VectorStep, ScalarStep}, FMFs, R.getDebugLoc()); | ||
VectorStep = Mul; | ||
VPI->replaceAllUsesWith(VectorStep); | ||
VPI->eraseFromParent(); | ||
lukel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.