Skip to content

Commit 4703c1c

Browse files
committed
nfnfc, use TypeSwitch
1 parent 4a158f6 commit 4703c1c

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
1111

1212
#include "VPlan.h"
13+
#include "llvm/ADT/TypeSwitch.h"
1314

1415
namespace llvm {
1516
class ScalarEvolution;
@@ -59,29 +60,37 @@ inline bool isSingleScalar(const VPValue *VPV) {
5960
if (VPV->isLiveIn())
6061
return true;
6162

62-
if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
63-
const VPRegionBlock *RegionOfR = Rep->getParent()->getParent();
64-
// Don't consider recipes in replicate regions as uniform yet; their first
65-
// lane cannot be accessed when executing the replicate region for other
66-
// lanes.
67-
if (RegionOfR && RegionOfR->isReplicator())
68-
return false;
69-
return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) &&
70-
all_of(Rep->operands(), isSingleScalar));
71-
}
72-
if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(VPV))
73-
return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
74-
if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
75-
return PreservesUniformity(WidenR->getOpcode()) &&
76-
all_of(WidenR->operands(), isSingleScalar);
77-
}
78-
if (auto *VPI = dyn_cast<VPInstruction>(VPV))
79-
return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
80-
(PreservesUniformity(VPI->getOpcode()) &&
81-
all_of(VPI->operands(), isSingleScalar));
82-
83-
// VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
84-
return isa<VPExpandSCEVRecipe>(VPV);
63+
return TypeSwitch<const VPValue *, bool>(VPV)
64+
.Case<VPReplicateRecipe>([&](const auto *Rep) {
65+
const VPRegionBlock *RegionOfR = Rep->getParent()->getParent();
66+
// Don't consider recipes in replicate regions as uniform yet; their
67+
// first lane cannot be accessed when executing the replicate region for
68+
// other lanes.
69+
if (RegionOfR && RegionOfR->isReplicator())
70+
return false;
71+
return Rep->isSingleScalar() ||
72+
(PreservesUniformity(Rep->getOpcode()) &&
73+
all_of(Rep->operands(), isSingleScalar));
74+
})
75+
.Case<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(
76+
[&](const auto *R) {
77+
return all_of(R->getDefiningRecipe()->operands(), isSingleScalar);
78+
})
79+
.Case<VPWidenRecipe>([&](const auto *WidenR) {
80+
return PreservesUniformity(WidenR->getOpcode()) &&
81+
all_of(WidenR->operands(), isSingleScalar);
82+
})
83+
.Case<VPInstruction>([&](const auto *VPI) {
84+
return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
85+
(PreservesUniformity(VPI->getOpcode()) &&
86+
all_of(VPI->operands(), isSingleScalar));
87+
})
88+
.Case<VPExpandSCEVRecipe>([](const VPValue *) {
89+
// VPExpandSCEVRecipes must be placed in the entry and are alway
90+
// uniform.
91+
return true;
92+
})
93+
.Default([](const VPValue *) { return false; });
8594
}
8695

8796
/// Return true if \p V is a header mask in \p Plan.

0 commit comments

Comments
 (0)