-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV] Added verification of EVL recipes #107630
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
Merged
npanchen
merged 2 commits into
llvm:main
from
nikolaypanchenko:npanchen/pr/vp_evl_verification
Sep 16, 2024
Merged
[LV] Added verification of EVL recipes #107630
npanchen
merged 2 commits into
llvm:main
from
nikolaypanchenko:npanchen/pr/vp_evl_verification
Sep 16, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-transforms Author: Kolya Panchenko (nikolaypanchenko) ChangesFull diff: https://github.com/llvm/llvm-project/pull/107630.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 765dc983cab4fb..afdea0b9f93030 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -18,6 +18,7 @@
#include "VPlanDominatorTree.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/CommandLine.h"
#define DEBUG_TYPE "loop-vectorize"
@@ -35,6 +36,11 @@ class VPlanVerifier {
// VPHeaderPHIRecipes.
bool verifyPhiRecipes(const VPBasicBlock *VPBB);
+ // Verify that \p EVL is used correctly. The user must be either in EVL-based
+ // recipes as a last operand or VPInstruction::Add which is incoming value
+ // into EVL's recipe.
+ bool verifyEVLRecipe(const VPInstruction &EVL) const;
+
bool verifyVPBasicBlock(const VPBasicBlock *VPBB);
bool verifyBlock(const VPBlockBase *VPB);
@@ -114,6 +120,67 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
return true;
}
+bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
+ if (EVL.getOpcode() != VPInstruction::ExplicitVectorLength) {
+ errs() << "verifyEVLRecipe should only be called on "
+ "VPInstruction::ExplicitVectorLength\n";
+ return false;
+ }
+ auto VerifyEVLUse = [&](const VPRecipeBase &R,
+ const unsigned ExpectedIdx) -> bool {
+ SmallVector<const VPValue *> Ops(R.operands());
+ unsigned UseCount = count(Ops, &EVL);
+ if (UseCount != 1 || Ops[ExpectedIdx] != &EVL) {
+ errs() << "EVL is used as non-last operand in EVL-based recipe\n";
+ return false;
+ }
+ return true;
+ };
+ for (const VPUser *U : EVL.users()) {
+ if (!TypeSwitch<const VPUser *, bool>(U)
+ .Case<VPWidenStoreEVLRecipe>([&](const VPWidenStoreEVLRecipe *S) {
+ return VerifyEVLUse(*S, 2);
+ })
+ .Case<VPWidenLoadEVLRecipe>([&](const VPWidenLoadEVLRecipe *L) {
+ return VerifyEVLUse(*L, 1);
+ })
+ .Case<VPWidenEVLRecipe>([&](const VPWidenEVLRecipe *W) {
+ return VerifyEVLUse(
+ *W, Instruction::isUnaryOp(W->getOpcode()) ? 1 : 2);
+ })
+ .Case<VPReductionEVLRecipe>([&](const VPReductionEVLRecipe *R) {
+ return VerifyEVLUse(*R, 2);
+ })
+ .Case<VPScalarCastRecipe>(
+ [&](const VPScalarCastRecipe *S) { return true; })
+ .Case<VPInstruction>([&](const VPInstruction *I) {
+ if (I->getOpcode() != Instruction::Add) {
+ errs()
+ << "EVL is used as an operand in non-VPInstruction::Add\n";
+ return false;
+ }
+ if (I->getNumUsers() != 1) {
+ errs() << "EVL is used in VPInstruction:Add with multiple "
+ "users\n";
+ return false;
+ }
+ if (!isa<VPEVLBasedIVPHIRecipe>(*I->users().begin())) {
+ errs() << "Result of VPInstruction::Add with EVL operand is "
+ "not used by VPEVLBasedIVPHIRecipe\n";
+ return false;
+ }
+ return true;
+ })
+ .Default([&](const VPUser *U) {
+ errs() << "EVL has unexpected user\n";
+ return false;
+ })) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
if (!verifyPhiRecipes(VPBB))
return false;
@@ -150,6 +217,13 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
}
}
}
+ if (const auto *EVL = dyn_cast<VPInstruction>(&R)) {
+ if (EVL->getOpcode() == VPInstruction::ExplicitVectorLength &&
+ !verifyEVLRecipe(*EVL)) {
+ errs() << "EVL VPValue is not used correctly\n";
+ return false;
+ }
+ }
}
auto *IRBB = dyn_cast<VPIRBasicBlock>(VPBB);
|
alexey-bataev
approved these changes
Sep 6, 2024
e83895e
to
160e21b
Compare
fhahn
approved these changes
Sep 13, 2024
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.
LGTM, thanks!
✅ With the latest revision this PR passed the C/C++ code formatter. |
d9e9d28
to
a70a4a0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.