-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[VPlanUtils] Use TypeSwitch to simplify isSingleScalar(). nfc #141074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-vectorizers Author: Mel Chen (Mel-Chen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/141074.diff 1 Files Affected:
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<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 *) {
+ // 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.
|
|
@llvm/pr-subscribers-llvm-transforms Author: Mel Chen (Mel-Chen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/141074.diff 1 Files Affected:
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<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 *) {
+ // 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.
|
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this is a regression in code readability, not an improvement.
We generally do not use TypeSwitch in llvm/, it looks like it leaked into VPlan (and VPlan only).
Ok, we can continue the work using if (isa<...>). |
No description provided.