-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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 15 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1019,6 +1019,14 @@ 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 = VPBuilder(&R).createWidenCast(Instruction::Trunc, X, WideStepTy); | ||
| R.getVPSingleValue()->replaceAllUsesWith(X); | ||
| } | ||
| } | ||
|
|
||
| void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) { | ||
|
|
@@ -2367,23 +2375,70 @@ void VPlanTransforms::createInterleaveGroups( | |
| } | ||
| } | ||
|
|
||
| void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan) { | ||
| void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan, | ||
| VPTypeAnalysis &TypeInfo) { | ||
|
||
| using namespace llvm::VPlanPatternMatch; | ||
|
|
||
| SmallVector<VPRecipeBase *> ToRemove; | ||
| 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); | ||
| ToRemove.push_back(PhiR); | ||
| 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(); | ||
|
|
||
| // Expand WideIVStep. | ||
| auto *VPI = cast<VPInstruction>(&R); | ||
| VPBuilder Builder(VPI); | ||
| 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); | ||
| ToRemove.push_back(VPI); | ||
| } | ||
| } | ||
|
|
||
| for (VPRecipeBase *R : ToRemove) | ||
| R->eraseFromParent(); | ||
| } | ||
|
|
||
| void VPlanTransforms::handleUncountableEarlyExit( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.