[llvm] [VPlanUtils] Use TypeSwitch to simplify isSingleScalar(). nfc (PR #141074)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri May 23 03:29:42 PDT 2025
================
@@ -59,29 +60,37 @@ inline bool isSingleScalar(const VPValue *VPV) {
if (VPV->isLiveIn())
return true;
- if (auto *Rep = dyn_cast<VPReplicateRecipe>(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<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(VPV))
- return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
- if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
- return PreservesUniformity(WidenR->getOpcode()) &&
- all_of(WidenR->operands(), isSingleScalar);
- }
- if (auto *VPI = dyn_cast<VPInstruction>(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<VPExpandSCEVRecipe>(VPV);
+ return TypeSwitch<const VPValue *, bool>(VPV)
+ .Case<VPReplicateRecipe>([&](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<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(
+ [&](const auto *R) {
+ return all_of(R->getDefiningRecipe()->operands(), isSingleScalar);
+ })
+ .Case<VPWidenRecipe>([&](const auto *WidenR) {
+ return PreservesUniformity(WidenR->getOpcode()) &&
+ all_of(WidenR->operands(), isSingleScalar);
+ })
+ .Case<VPInstruction>([&](const auto *VPI) {
+ return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
+ (PreservesUniformity(VPI->getOpcode()) &&
+ all_of(VPI->operands(), isSingleScalar));
+ })
+ .Case<VPExpandSCEVRecipe>([](const VPValue *) {
----------------
Mel-Chen wrote:
8e441c293ac2424e679a2780852d0eb665a7af94
https://github.com/llvm/llvm-project/pull/141074
More information about the llvm-commits
mailing list