-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Fix header phi VPInstruction verification. NFC #151472
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
[VPlan] Fix header phi VPInstruction verification. NFC #151472
Conversation
Noticed this when checking the invariant that all phis in the header block must be header phis. I think there's a missing set of parentheses here, since otherwise it only cast<VPInstruction> when RecipeI isn't a VPInstruction.
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: Luke Lau (lukel97) ChangesNoticed this when checking the invariant that all phis in the header block must be header phis. I think there's a missing set of parentheses here, since otherwise it only cast<VPInstruction> when RecipeI isn't a VPInstruction. Full diff: https://github.com/llvm/llvm-project/pull/151472.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 57d01cbefbe26..b0de97ac5618d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -80,8 +80,8 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
NumActiveLaneMaskPhiRecipes++;
if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) &&
- !isa<VPInstruction>(*RecipeI) &&
- cast<VPInstruction>(RecipeI)->getOpcode() == Instruction::PHI) {
+ !(isa<VPInstruction>(*RecipeI) &&
+ cast<VPInstruction>(RecipeI)->getOpcode() == Instruction::PHI)) {
errs() << "Found non-header PHI recipe in header VPBB";
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
errs() << ": ";
|
Mel-Chen
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.
LGTM, but I'd like to know if there's a way to find a test case to verify this?
fhahn
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.
Can you add a test with a non-header-phi in header block to llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp?
I guess at the moment this would just be VPPredInstPHI?
| if (isa<VPActiveLaneMaskPHIRecipe>(RecipeI)) | ||
| NumActiveLaneMaskPhiRecipes++; | ||
|
|
||
| if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) && |
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.
| if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) && | |
| if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPhi>(*RecipeI) && |
This can just use VPPhi I think.
| if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) && | ||
| !isa<VPInstruction>(*RecipeI) && | ||
| cast<VPInstruction>(RecipeI)->getOpcode() == Instruction::PHI) { | ||
| !(isa<VPInstruction>(*RecipeI) && |
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.
Looking at the definition of isPhi it seems like we're missing tests where we have a VPPredInstPHIRecipe in the header VPBB, since that seems to be the only one (besides VPInstructions) where isPhi would return true and isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) would return false.
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.
But looking at VPPredInstPHIRecipe it seems unlikely to be in the header, right? So perhaps there is no way to write a test case that proves this was broken.
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.
I think a VPIRPhi, i.e a VPIRInstruction with a PHI opcode should also be caught by this, I've added a test case for it in c170996
I added a test case in c170996 before I saw your comment, I think VPIRPhis are considered a non-header-phi too. |
artagnon
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.
Thanks for adding the test! I will let one of the other reviewers sign off on this.
| new VPInstruction(VPInstruction::BranchOnCond, {CanIV}); | ||
|
|
||
| VPBasicBlock *VPBB1 = Plan.getEntry(); | ||
| VPBasicBlock *VPBB2 = Plan.createVPBasicBlock(""); |
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.
| VPBasicBlock *VPBB2 = Plan.createVPBasicBlock(""); | |
| VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("entry"); |
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.
VPBB2 is the vector header block, so I named it "header"
fhahn
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.
LGTM, thanks
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/30229 Here is the relevant piece of the build log for the reference |
|
Looks like I need to change the expected output in the test whenever dumping isn't defined, working on a fix now. |
|
Maybe just do a prefix-matching? |
I wish I could, but doesn't look like there's a GTEST macro for prefixes unfortunately. I've just copied what the other tests have done and pushed a fix in 3e579d9 |
…152336) This PR fixes the issue that caused an ub in PR #151472. The issue was a shl call taking a negative shift amount (posDiff). The result was never used, but tablegen would perform the calculation anyway. The fix was to replace the shl call with just multiplications with constants. Original PR description: This patch improves the helper classes in the SpacemiT-X60 vector scheduling model and will be used in follow-up PRs: There are now two functions to map LMUL to values: * ConstValueUntilLMULThenDoubleBase: returns BaseValue for LMUL values before startLMUL, Value for startLMUL, then doubles Value for each subsequent LMUL. Useful for cases where fractional LMULs have constant cycles, and integer LMULs double as they increase. * GetLMULValue: takes an ordered list of LMUL cycles and LMUL and returns the corresponding cycle. Useful for cases we can't easily cover with ConstValueUntilLMULThenDoubleBase. This PR also adds some useful simplified versions of ConstValueUntilLMULThenDoubleBase, e.g.: ConstValueUntilLMULThenDouble (when BaseValue == Value), or ConstOneUntilMF4ThenDouble (when cycles start to double after MF2)
…lvm#152336) This PR fixes the issue that caused an ub in PR llvm#151472. The issue was a shl call taking a negative shift amount (posDiff). The result was never used, but tablegen would perform the calculation anyway. The fix was to replace the shl call with just multiplications with constants. Original PR description: This patch improves the helper classes in the SpacemiT-X60 vector scheduling model and will be used in follow-up PRs: There are now two functions to map LMUL to values: * ConstValueUntilLMULThenDoubleBase: returns BaseValue for LMUL values before startLMUL, Value for startLMUL, then doubles Value for each subsequent LMUL. Useful for cases where fractional LMULs have constant cycles, and integer LMULs double as they increase. * GetLMULValue: takes an ordered list of LMUL cycles and LMUL and returns the corresponding cycle. Useful for cases we can't easily cover with ConstValueUntilLMULThenDoubleBase. This PR also adds some useful simplified versions of ConstValueUntilLMULThenDoubleBase, e.g.: ConstValueUntilLMULThenDouble (when BaseValue == Value), or ConstOneUntilMF4ThenDouble (when cycles start to double after MF2)
Noticed this when checking the invariant that all phis in the header block must be header phis. I think there's a missing set of parentheses here, since otherwise it only cast when RecipeI isn't a VPInstruction.