diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index 28c1a6af2570b..7df6370c8ed6d 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,35 @@ 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->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 auto *) { + // VPExpandSCEVRecipes must be placed in the entry and are always + // uniform. + return true; + }) + .Default([](const auto *) { return false; }); } /// Return true if \p V is a header mask in \p Plan.