[llvm] [VPlan] Simplify branch on False in VPlan transform (NFC). (PR #140409)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat May 31 05:17:47 PDT 2025
================
@@ -1841,43 +1841,39 @@ void VPlanTransforms::truncateToMinimalBitwidths(
}
}
-/// Remove BranchOnCond recipes with true conditions together with removing
-/// dead edges to their successors.
-static void removeBranchOnCondTrue(VPlan &Plan) {
+/// Remove BranchOnCond recipes with true or false conditions together with
+/// removing dead edges to their successors.
+static void removeBranchOnConst(VPlan &Plan) {
using namespace llvm::VPlanPatternMatch;
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_shallow(Plan.getEntry()))) {
+ VPValue *Cond;
if (VPBB->getNumSuccessors() != 2 || VPBB == Plan.getEntry() ||
- !match(&VPBB->back(), m_BranchOnCond(m_True())))
+ !match(&VPBB->back(), m_BranchOnCond(m_VPValue(Cond))))
continue;
- VPBasicBlock *RemovedSucc = cast<VPBasicBlock>(VPBB->getSuccessors()[1]);
+ unsigned RemovedIdx;
+ if (match(Cond, m_True()))
+ RemovedIdx = 1;
+ else if (match(Cond, m_False()))
+ RemovedIdx = 0;
+ else
+ continue;
+
+ VPBasicBlock *RemovedSucc =
+ cast<VPBasicBlock>(VPBB->getSuccessors()[RemovedIdx]);
const auto &Preds = RemovedSucc->getPredecessors();
assert(count(Preds, VPBB) == 1 &&
"There must be a single edge between VPBB and its successor");
- unsigned DeadIdx = std::distance(Preds.begin(), find(Preds, VPBB));
-
- // Values coming from VPBB into ResumePhi recipes of RemoveSucc are removed
- // from these recipes.
+ // Values coming from VPBB into phi recipes of RemoveSucc are removed from
+ // these recipes.
for (VPRecipeBase &R : make_early_inc_range(*RemovedSucc)) {
- assert((!isa<VPIRInstruction>(&R) ||
- !isa<PHINode>(cast<VPIRInstruction>(&R)->getInstruction())) &&
- !isa<VPHeaderPHIRecipe>(&R) &&
- "Cannot update VPIRInstructions wrapping phis or header phis yet");
- auto *VPI = dyn_cast<VPPhi>(&R);
- if (!VPI)
+ auto *Phi = dyn_cast<VPPhiAccessors>(&R);
+ if (!Phi)
break;
----------------
fhahn wrote:
Done thanks! Switched to using `cast<>`.
https://github.com/llvm/llvm-project/pull/140409
More information about the llvm-commits
mailing list