From 4703c1c88f5bed3c38b328e961b82b6798aa06aa Mon Sep 17 00:00:00 2001 From: Mel Chen Date: Thu, 22 May 2025 06:24:43 -0700 Subject: [PATCH 1/4] nfnfc, use TypeSwitch --- llvm/lib/Transforms/Vectorize/VPlanUtils.h | 55 +++++++++++++--------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index 28c1a6af2570b..5aa0b0ecea9aa 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h +++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h @@ -10,6 +10,7 @@ #define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H #include "VPlan.h" +#include "llvm/ADT/TypeSwitch.h" namespace llvm { class ScalarEvolution; @@ -59,29 +60,37 @@ inline bool isSingleScalar(const VPValue *VPV) { if (VPV->isLiveIn()) return true; - if (auto *Rep = dyn_cast(VPV)) { - const VPRegionBlock *RegionOfR = Rep->getParent()->getParent(); - // Don't consider recipes in replicate regions as uniform yet; their first - // lane cannot be accessed when executing the replicate region for other - // lanes. - if (RegionOfR && RegionOfR->isReplicator()) - return false; - return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) && - all_of(Rep->operands(), isSingleScalar)); - } - if (isa(VPV)) - return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar); - if (auto *WidenR = dyn_cast(VPV)) { - return PreservesUniformity(WidenR->getOpcode()) && - all_of(WidenR->operands(), isSingleScalar); - } - if (auto *VPI = dyn_cast(VPV)) - return VPI->isSingleScalar() || VPI->isVectorToScalar() || - (PreservesUniformity(VPI->getOpcode()) && - all_of(VPI->operands(), isSingleScalar)); - - // VPExpandSCEVRecipes must be placed in the entry and are alway uniform. - return isa(VPV); + return TypeSwitch(VPV) + .Case([&](const auto *Rep) { + const VPRegionBlock *RegionOfR = Rep->getParent()->getParent(); + // Don't consider recipes in replicate regions as uniform yet; their + // first lane cannot be accessed when executing the replicate region for + // other lanes. + if (RegionOfR && RegionOfR->isReplicator()) + return false; + return Rep->isSingleScalar() || + (PreservesUniformity(Rep->getOpcode()) && + all_of(Rep->operands(), isSingleScalar)); + }) + .Case( + [&](const auto *R) { + return all_of(R->getDefiningRecipe()->operands(), isSingleScalar); + }) + .Case([&](const auto *WidenR) { + return PreservesUniformity(WidenR->getOpcode()) && + all_of(WidenR->operands(), isSingleScalar); + }) + .Case([&](const auto *VPI) { + return VPI->isSingleScalar() || VPI->isVectorToScalar() || + (PreservesUniformity(VPI->getOpcode()) && + all_of(VPI->operands(), isSingleScalar)); + }) + .Case([](const VPValue *) { + // VPExpandSCEVRecipes must be placed in the entry and are alway + // uniform. + return true; + }) + .Default([](const VPValue *) { return false; }); } /// Return true if \p V is a header mask in \p Plan. From 6be5da5989d876008e37ee3b98d297a40fcb28c1 Mon Sep 17 00:00:00 2001 From: Mel Chen Date: Fri, 23 May 2025 03:16:49 -0700 Subject: [PATCH 2/4] nfc, correct comment --- llvm/lib/Transforms/Vectorize/VPlanUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index 5aa0b0ecea9aa..2647ef4b70124 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h +++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h @@ -86,7 +86,7 @@ inline bool isSingleScalar(const VPValue *VPV) { all_of(VPI->operands(), isSingleScalar)); }) .Case([](const VPValue *) { - // VPExpandSCEVRecipes must be placed in the entry and are alway + // VPExpandSCEVRecipes must be placed in the entry and are always // uniform. return true; }) From d8da3b425e075ae20db30c92f9517506ece66cd5 Mon Sep 17 00:00:00 2001 From: Mel Chen Date: Fri, 23 May 2025 03:26:52 -0700 Subject: [PATCH 3/4] nfc, remove getDefiningRecipe() --- llvm/lib/Transforms/Vectorize/VPlanUtils.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index 2647ef4b70124..dbac50bcce717 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h +++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h @@ -73,9 +73,7 @@ inline bool isSingleScalar(const VPValue *VPV) { all_of(Rep->operands(), isSingleScalar)); }) .Case( - [&](const auto *R) { - return all_of(R->getDefiningRecipe()->operands(), isSingleScalar); - }) + [&](const auto *R) { return all_of(R->operands(), isSingleScalar); }) .Case([&](const auto *WidenR) { return PreservesUniformity(WidenR->getOpcode()) && all_of(WidenR->operands(), isSingleScalar); From 8e441c293ac2424e679a2780852d0eb665a7af94 Mon Sep 17 00:00:00 2001 From: Mel Chen Date: Fri, 23 May 2025 03:27:50 -0700 Subject: [PATCH 4/4] nfc, replace VPValue with auto --- llvm/lib/Transforms/Vectorize/VPlanUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index dbac50bcce717..7df6370c8ed6d 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h +++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h @@ -83,12 +83,12 @@ inline bool isSingleScalar(const VPValue *VPV) { (PreservesUniformity(VPI->getOpcode()) && all_of(VPI->operands(), isSingleScalar)); }) - .Case([](const VPValue *) { + .Case([](const auto *) { // VPExpandSCEVRecipes must be placed in the entry and are always // uniform. return true; }) - .Default([](const VPValue *) { return false; }); + .Default([](const auto *) { return false; }); } /// Return true if \p V is a header mask in \p Plan.