-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Remove unused first mask op from VPBlendRecipe. #87770
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
fhahn
merged 8 commits into
llvm:main
from
fhahn:vplan-remove-unused-first-mask-for-blend
Apr 9, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ef8f73
[VPlan] Remove unused first mask op from VPBlendRecipe.
fhahn 5df5b88
Merge remote-tracking branch 'origin/main' into vplan-remove-unused-f…
fhahn e7ba896
Merge remote-tracking branch 'origin/main' into vplan-remove-unused-f…
fhahn 1f3ef01
!fixup address latest comments, thanks!
fhahn b0c973c
!fixup update unittest.
fhahn d698777
!fixup remove redundant check
fhahn 48bab18
!fixup add TODO toskip most expensive mask.
fhahn 972e521
@!fixup fix formatting
fhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1932,14 +1932,12 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe { | |
class VPBlendRecipe : public VPSingleDefRecipe { | ||
public: | ||
/// The blend operation is a User of the incoming values and of their | ||
/// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value | ||
/// might be incoming with a full mask for which there is no VPValue. | ||
/// respective masks, ordered [I0, I1, M1, I2, M2, ...]. Note that the first | ||
/// incoming value does not have a mask associated. | ||
VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands) | ||
: VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, Phi->getDebugLoc()) { | ||
assert(Operands.size() > 0 && | ||
((Operands.size() == 1) || (Operands.size() % 2 == 0)) && | ||
"Expected either a single incoming value or a positive even number " | ||
"of operands"); | ||
assert((Operands.size() + 1) % 2 == 0 && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is this better than asserting that the number of operands is odd by |
||
"Expected an odd number of operands"); | ||
} | ||
|
||
VPRecipeBase *clone() override { | ||
|
@@ -1949,15 +1947,20 @@ class VPBlendRecipe : public VPSingleDefRecipe { | |
|
||
VP_CLASSOF_IMPL(VPDef::VPBlendSC) | ||
|
||
/// Return the number of incoming values, taking into account that a single | ||
/// Return the number of incoming values, taking into account that the first | ||
/// incoming value has no mask. | ||
unsigned getNumIncomingValues() const { return (getNumOperands() + 1) / 2; } | ||
|
||
/// Return incoming value number \p Idx. | ||
VPValue *getIncomingValue(unsigned Idx) const { return getOperand(Idx * 2); } | ||
VPValue *getIncomingValue(unsigned Idx) const { | ||
return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - 1); | ||
} | ||
|
||
/// Return mask number \p Idx. | ||
VPValue *getMask(unsigned Idx) const { return getOperand(Idx * 2 + 1); } | ||
VPValue *getMask(unsigned Idx) const { | ||
assert(Idx > 0 && "First index has no mask associated."); | ||
return getOperand(Idx * 2); | ||
} | ||
|
||
/// Generate the phi/select nodes. | ||
void execute(VPTransformState &State) override; | ||
|
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
nit: may be better to early-continue earlier - before creating the edge mask, which for first operand is needed only to assert, and for other operands can simplify the assert. Can also simplify simplifyRecipe() to look for single-operand Blends, by doing, e.g.,
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.
Unfortunately we can't use an early continue at the top, as null masks cannot be added as operands due to them not being proper VPValues. The early continue would mean we break after adding 2 incoming values but no mask. Left as is for now, but pushed 9430a4b to replace
createEdgeMask
to withgetEdgeMask
to make it clear that no new edge-mask is created, only the existing one retrieved.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.
Good catch!
Hence the restructuring proposed above, which may look clearer, early returning after inserting the first operand (w/o its mask) if all operands are the same. Otherwise the masks must be non-null. This takes care of simplifyRecipe(), leaving it to do copy elimination (remove blends of a single element).