- Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Introduce m_[Specific]ICmp matcher #151540
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
Conversation
| @llvm/pr-subscribers-llvm-transforms Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/151540.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h index d133610ef4f75..7e6d83c09f860 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h +++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h @@ -461,6 +461,12 @@ m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) { return m_BinaryOr<Op0_t, Op1_t, /*Commutative*/ true>(Op0, Op1); } +template <typename Op0_t, typename Op1_t> +inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::ICmp, false> +m_ICmp(const Op0_t &Op0, const Op1_t &Op1) { + return m_Binary<Instruction::ICmp, Op0_t, Op1_t, false>(Op0, Op1); +} + template <typename Op0_t, typename Op1_t> using GEPLikeRecipe_match = BinaryRecipe_match<Op0_t, Op1_t, Instruction::GetElementPtr, false, diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index a1d12a3a01e5e..253144e64f9f1 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1383,11 +1383,10 @@ static bool optimizeVectorInductionWidthForTCAndVFUF(VPlan &Plan, // Currently only handle cases where the single user is a header-mask // comparison with the backedge-taken-count. - if (!match( - *WideIV->user_begin(), - m_Binary<Instruction::ICmp>( - m_Specific(WideIV), - m_Broadcast(m_Specific(Plan.getOrCreateBackedgeTakenCount()))))) + if (!match(*WideIV->user_begin(), + m_ICmp(m_Specific(WideIV), + m_Broadcast( + m_Specific(Plan.getOrCreateBackedgeTakenCount()))))) continue; // Update IV operands and comparison bound to use new narrower type. @@ -1420,9 +1419,8 @@ static bool isConditionTrueViaVFAndUF(VPValue *Cond, VPlan &Plan, }); auto *CanIV = Plan.getCanonicalIV(); - if (!match(Cond, m_Binary<Instruction::ICmp>( - m_Specific(CanIV->getBackedgeValue()), - m_Specific(&Plan.getVectorTripCount()))) || + if (!match(Cond, m_ICmp(m_Specific(CanIV->getBackedgeValue()), + m_Specific(&Plan.getVectorTripCount()))) || cast<VPRecipeWithIRFlags>(Cond->getDefiningRecipe())->getPredicate() != CmpInst::ICMP_EQ) return false; @@ -1835,7 +1833,7 @@ void VPlanTransforms::truncateToMinimalBitwidths( VPW->dropPoisonGeneratingFlags(); if (OldResSizeInBits != NewResSizeInBits && - !match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue()))) { + !match(&R, m_ICmp(m_VPValue(), m_VPValue()))) { // Extend result to original width. auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); @@ -1844,9 +1842,8 @@ void VPlanTransforms::truncateToMinimalBitwidths( Ext->setOperand(0, ResultVPV); assert(OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"); } else { - assert( - match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue())) && - "Only ICmps should not need extending the result."); + assert(match(&R, m_ICmp(m_VPValue(), m_VPValue())) && + "Only ICmps should not need extending the result."); } assert(!isa<VPWidenStoreRecipe>(&R) && "stores cannot be narrowed"); |
| @llvm/pr-subscribers-vectorizers Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/151540.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h index d133610ef4f75..7e6d83c09f860 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h +++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h @@ -461,6 +461,12 @@ m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) { return m_BinaryOr<Op0_t, Op1_t, /*Commutative*/ true>(Op0, Op1); } +template <typename Op0_t, typename Op1_t> +inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::ICmp, false> +m_ICmp(const Op0_t &Op0, const Op1_t &Op1) { + return m_Binary<Instruction::ICmp, Op0_t, Op1_t, false>(Op0, Op1); +} + template <typename Op0_t, typename Op1_t> using GEPLikeRecipe_match = BinaryRecipe_match<Op0_t, Op1_t, Instruction::GetElementPtr, false, diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index a1d12a3a01e5e..253144e64f9f1 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1383,11 +1383,10 @@ static bool optimizeVectorInductionWidthForTCAndVFUF(VPlan &Plan, // Currently only handle cases where the single user is a header-mask // comparison with the backedge-taken-count. - if (!match( - *WideIV->user_begin(), - m_Binary<Instruction::ICmp>( - m_Specific(WideIV), - m_Broadcast(m_Specific(Plan.getOrCreateBackedgeTakenCount()))))) + if (!match(*WideIV->user_begin(), + m_ICmp(m_Specific(WideIV), + m_Broadcast( + m_Specific(Plan.getOrCreateBackedgeTakenCount()))))) continue; // Update IV operands and comparison bound to use new narrower type. @@ -1420,9 +1419,8 @@ static bool isConditionTrueViaVFAndUF(VPValue *Cond, VPlan &Plan, }); auto *CanIV = Plan.getCanonicalIV(); - if (!match(Cond, m_Binary<Instruction::ICmp>( - m_Specific(CanIV->getBackedgeValue()), - m_Specific(&Plan.getVectorTripCount()))) || + if (!match(Cond, m_ICmp(m_Specific(CanIV->getBackedgeValue()), + m_Specific(&Plan.getVectorTripCount()))) || cast<VPRecipeWithIRFlags>(Cond->getDefiningRecipe())->getPredicate() != CmpInst::ICMP_EQ) return false; @@ -1835,7 +1833,7 @@ void VPlanTransforms::truncateToMinimalBitwidths( VPW->dropPoisonGeneratingFlags(); if (OldResSizeInBits != NewResSizeInBits && - !match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue()))) { + !match(&R, m_ICmp(m_VPValue(), m_VPValue()))) { // Extend result to original width. auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); @@ -1844,9 +1842,8 @@ void VPlanTransforms::truncateToMinimalBitwidths( Ext->setOperand(0, ResultVPV); assert(OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"); } else { - assert( - match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue())) && - "Only ICmps should not need extending the result."); + assert(match(&R, m_ICmp(m_VPValue(), m_VPValue())) && + "Only ICmps should not need extending the result."); } assert(!isa<VPWidenStoreRecipe>(&R) && "stores cannot be narrowed"); |
| I think we want to match the CmpPredicate here? |
fhahn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this should also allow capturing the predicate
lukel97 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just noting that we don't seem to bind the condition code anywhere anymore but I think that's fine, it's good to keep things in sync with LLVM IR's patternmatch
fhahn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
No description provided.