From c088b6a0d3dcf613a53b95a4844d4cf2ced193d5 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 24 Jul 2025 14:08:39 +0100 Subject: [PATCH 1/2] [VPlan] Improve code in VPlanPredicator (NFC) --- llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp index f0cab79197b4d..8d6d93c9d46b4 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp @@ -133,8 +133,8 @@ VPValue *VPPredicator::createBlockInMask(VPBasicBlock *VPBB) { // load/store/gather/scatter. Initialize BlockMask to no-mask. VPValue *BlockMask = nullptr; // This is the block mask. We OR all unique incoming edges. - for (auto *Predecessor : SetVector( - VPBB->getPredecessors().begin(), VPBB->getPredecessors().end())) { + for (auto *Predecessor : make_range(VPBB->getPredecessors().begin(), + unique(VPBB->getPredecessors()))) { VPValue *EdgeMask = createEdgeMask(cast(Predecessor), VPBB); if (!EdgeMask) { // Mask of predecessor is all-one so mask of block is // too. @@ -184,8 +184,7 @@ void VPPredicator::createSwitchEdgeMasks(VPInstruction *SI) { VPValue *Cond = SI->getOperand(0); VPBasicBlock *DefaultDst = cast(Src->getSuccessors()[0]); MapVector> Dst2Compares; - for (const auto &[Idx, Succ] : - enumerate(ArrayRef(Src->getSuccessors()).drop_front())) { + for (const auto &[Idx, Succ] : enumerate(drop_begin(Src->getSuccessors()))) { VPBasicBlock *Dst = cast(Succ); assert(!getEdgeMask(Src, Dst) && "Edge masks already created"); // Cases whose destination is the same as default are redundant and can @@ -206,7 +205,7 @@ void VPPredicator::createSwitchEdgeMasks(VPInstruction *SI) { // cases with destination == Dst are taken. Join the conditions for each // case whose destination == Dst using an OR. VPValue *Mask = Conds[0]; - for (VPValue *V : ArrayRef(Conds).drop_front()) + for (VPValue *V : drop_begin(Conds)) Mask = Builder.createOr(Mask, V); if (SrcMask) Mask = Builder.createLogicalAnd(SrcMask, Mask); From 94b24440aab068b61ad668d9a9cd22328db557d5 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 24 Jul 2025 14:26:41 +0100 Subject: [PATCH 2/2] [VPlan] Fix unique-related thinko --- llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp index 8d6d93c9d46b4..fc8458ce0ce8e 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp @@ -133,8 +133,8 @@ VPValue *VPPredicator::createBlockInMask(VPBasicBlock *VPBB) { // load/store/gather/scatter. Initialize BlockMask to no-mask. VPValue *BlockMask = nullptr; // This is the block mask. We OR all unique incoming edges. - for (auto *Predecessor : make_range(VPBB->getPredecessors().begin(), - unique(VPBB->getPredecessors()))) { + for (auto *Predecessor : SetVector( + VPBB->getPredecessors().begin(), VPBB->getPredecessors().end())) { VPValue *EdgeMask = createEdgeMask(cast(Predecessor), VPBB); if (!EdgeMask) { // Mask of predecessor is all-one so mask of block is // too.