Skip to content

Commit 869c76d

Browse files
authored
[VPlan] Allow zero-operand m_BranchOn(Cond|Count) (NFC) (#162721)
1 parent 7314565 commit 869c76d

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,9 @@ static bool hasConditionalTerminator(const VPBasicBlock *VPBB) {
635635
const VPRecipeBase *R = &VPBB->back();
636636
bool IsSwitch = isa<VPInstruction>(R) &&
637637
cast<VPInstruction>(R)->getOpcode() == Instruction::Switch;
638-
bool IsCondBranch = isa<VPBranchOnMaskRecipe>(R) ||
639-
match(R, m_BranchOnCond(m_VPValue())) ||
640-
match(R, m_BranchOnCount(m_VPValue(), m_VPValue()));
638+
bool IsCondBranch =
639+
isa<VPBranchOnMaskRecipe>(R) ||
640+
match(R, m_CombineOr(m_BranchOnCond(), m_BranchOnCount()));
641641
(void)IsCondBranch;
642642
(void)IsSwitch;
643643
if (VPBB->getNumSuccessors() == 2 ||

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, VPBasicBlock *HeaderVPBB,
433433
// We are about to replace the branch to exit the region. Remove the original
434434
// BranchOnCond, if there is any.
435435
DebugLoc LatchDL = DL;
436-
if (!LatchVPBB->empty() &&
437-
match(&LatchVPBB->back(), m_BranchOnCond(m_VPValue()))) {
436+
if (!LatchVPBB->empty() && match(&LatchVPBB->back(), m_BranchOnCond())) {
438437
LatchDL = LatchVPBB->getTerminator()->getDebugLoc();
439438
LatchVPBB->getTerminator()->eraseFromParent();
440439
}
@@ -875,8 +874,7 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
875874
Plan.getVectorLoopRegion()->getEntryBasicBlock())) {
876875
auto *VPBB = cast<VPBasicBlock>(VPB);
877876
for (auto &R : *VPBB) {
878-
if (R.mayWriteToMemory() &&
879-
!match(&R, m_BranchOnCount(m_VPValue(), m_VPValue())))
877+
if (R.mayWriteToMemory() && !match(&R, m_BranchOnCount()))
880878
return false;
881879
}
882880
}

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ m_Freeze(const Op0_t &Op0) {
344344
return m_VPInstruction<Instruction::Freeze>(Op0);
345345
}
346346

347+
inline VPInstruction_match<VPInstruction::BranchOnCond> m_BranchOnCond() {
348+
return m_VPInstruction<VPInstruction::BranchOnCond>();
349+
}
350+
347351
template <typename Op0_t>
348352
inline VPInstruction_match<VPInstruction::BranchOnCond, Op0_t>
349353
m_BranchOnCond(const Op0_t &Op0) {
@@ -374,6 +378,10 @@ m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
374378
return m_VPInstruction<VPInstruction::ActiveLaneMask>(Op0, Op1, Op2);
375379
}
376380

381+
inline VPInstruction_match<VPInstruction::BranchOnCount> m_BranchOnCount() {
382+
return m_VPInstruction<VPInstruction::BranchOnCount>();
383+
}
384+
377385
template <typename Op0_t, typename Op1_t>
378386
inline VPInstruction_match<VPInstruction::BranchOnCount, Op0_t, Op1_t>
379387
m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF,
16581658
auto *Term = &ExitingVPBB->back();
16591659
VPValue *Cond;
16601660
ScalarEvolution &SE = *PSE.getSE();
1661-
if (match(Term, m_BranchOnCount(m_VPValue(), m_VPValue())) ||
1661+
if (match(Term, m_BranchOnCount()) ||
16621662
match(Term, m_BranchOnCond(m_Not(m_ActiveLaneMask(
16631663
m_VPValue(), m_VPValue(), m_VPValue()))))) {
16641664
// Try to simplify the branch condition if TC <= VF * UF when the latch
@@ -3398,9 +3398,8 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
33983398

33993399
VPBuilder Builder(LatchVPBB->getTerminator());
34003400
VPBlockBase *TrueSucc = EarlyExitingVPBB->getSuccessors()[0];
3401-
assert(
3402-
match(EarlyExitingVPBB->getTerminator(), m_BranchOnCond(m_VPValue())) &&
3403-
"Terminator must be be BranchOnCond");
3401+
assert(match(EarlyExitingVPBB->getTerminator(), m_BranchOnCond()) &&
3402+
"Terminator must be be BranchOnCond");
34043403
VPValue *CondOfEarlyExitingVPBB =
34053404
EarlyExitingVPBB->getTerminator()->getOperand(0);
34063405
auto *CondToEarlyExit = TrueSucc == EarlyExitVPBB
@@ -4009,8 +4008,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
40094008
unsigned VFMinVal = VF.getKnownMinValue();
40104009
SmallVector<VPInterleaveRecipe *> StoreGroups;
40114010
for (auto &R : *VectorLoop->getEntryBasicBlock()) {
4012-
if (isa<VPCanonicalIVPHIRecipe>(&R) ||
4013-
match(&R, m_BranchOnCount(m_VPValue(), m_VPValue())))
4011+
if (isa<VPCanonicalIVPHIRecipe>(&R) || match(&R, m_BranchOnCount()))
40144012
continue;
40154013

40164014
if (isa<VPDerivedIVRecipe, VPScalarIVStepsRecipe>(&R) &&

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ void UnrollState::unrollHeaderPHIByUF(VPHeaderPHIRecipe *R,
259259

260260
/// Handle non-header-phi recipes.
261261
void UnrollState::unrollRecipeByUF(VPRecipeBase &R) {
262-
if (match(&R, m_BranchOnCond(m_VPValue())) ||
263-
match(&R, m_BranchOnCount(m_VPValue(), m_VPValue())))
262+
if (match(&R, m_CombineOr(m_BranchOnCond(), m_BranchOnCount())))
264263
return;
265264

266265
if (auto *VPI = dyn_cast<VPInstruction>(&R)) {

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define DEBUG_TYPE "loop-vectorize"
2525

2626
using namespace llvm;
27+
using namespace VPlanPatternMatch;
2728

2829
namespace {
2930
class VPlanVerifier {
@@ -198,7 +199,6 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
198199
}
199200
// EVLIVIncrement is only used by EVLIV & BranchOnCount.
200201
// Having more than two users is unexpected.
201-
using namespace llvm::VPlanPatternMatch;
202202
if (I->getOpcode() != VPInstruction::Broadcast &&
203203
I->getNumUsers() != 1 &&
204204
(I->getNumUsers() != 2 ||
@@ -479,8 +479,7 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
479479
}
480480

481481
auto *LastInst = dyn_cast<VPInstruction>(std::prev(Exiting->end()));
482-
if (!LastInst || (LastInst->getOpcode() != VPInstruction::BranchOnCount &&
483-
LastInst->getOpcode() != VPInstruction::BranchOnCond)) {
482+
if (!match(LastInst, m_CombineOr(m_BranchOnCond(), m_BranchOnCount()))) {
484483
errs() << "VPlan vector loop exit must end with BranchOnCount or "
485484
"BranchOnCond VPInstruction\n";
486485
return false;

0 commit comments

Comments
 (0)