-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (part 1) #143102
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
Open
bjope
wants to merge
1
commit into
main
Choose a base branch
from
users/bjope/insertundef_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+757
−248
Open
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -7952,23 +7952,42 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, | |
// INSERT_VECTOR_ELT into out-of-bounds element is an UNDEF, except | ||
// for scalable vectors where we will generate appropriate code to | ||
// deal with out-of-bounds cases correctly. | ||
if (N3C && N1.getValueType().isFixedLengthVector() && | ||
N3C->getZExtValue() >= N1.getValueType().getVectorNumElements()) | ||
if (N3C && VT.isFixedLengthVector() && | ||
N3C->getZExtValue() >= VT.getVectorNumElements()) | ||
return getUNDEF(VT); | ||
|
||
// Undefined index can be assumed out-of-bounds, so that's UNDEF too. | ||
if (N3.isUndef()) | ||
return getUNDEF(VT); | ||
|
||
// If the inserted element is an UNDEF, just use the input vector. | ||
if (N2.isUndef()) | ||
// If inserting poison, just use the input vector. | ||
if (N2.getOpcode() == ISD::POISON) | ||
return N1; | ||
|
||
// Inserting undef into undef/poison is still undef. | ||
if (N2.getOpcode() == ISD::UNDEF && N1.isUndef()) | ||
return getUNDEF(VT); | ||
|
||
// If the inserted element is an UNDEF, just use the input vector. | ||
// But not if skipping the insert could make the result more poisonous. | ||
if (N2.isUndef()) { | ||
if (N3C && VT.isFixedLengthVector()) { | ||
APInt EltMask = | ||
APInt::getOneBitSet(VT.getVectorNumElements(), N3C->getZExtValue()); | ||
if (isGuaranteedNotToBePoison(N1, EltMask)) | ||
return N1; | ||
} else if (isGuaranteedNotToBePoison(N1)) | ||
return N1; | ||
} | ||
break; | ||
} | ||
case ISD::INSERT_SUBVECTOR: { | ||
// Inserting undef into undef is still undef. | ||
if (N1.isUndef() && N2.isUndef()) | ||
// If inserting poison, just use the input vector, | ||
if (N2.getOpcode() == ISD::POISON) | ||
return N1; | ||
|
||
// Inserting undef into undef/poison is still undef. | ||
if (N2.getOpcode() == ISD::UNDEF && N1.isUndef()) | ||
return getUNDEF(VT); | ||
|
||
EVT N2VT = N2.getValueType(); | ||
|
@@ -7997,11 +8016,37 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, | |
if (VT == N2VT) | ||
return N2; | ||
|
||
// If this is an insert of an extracted vector into an undef vector, we | ||
// can just use the input to the extract. | ||
// If this is an insert of an extracted vector into an undef/poison vector, | ||
// we can just use the input to the extract. But not if skipping the | ||
// extract+insert could make the result more poisonous. | ||
if (N1.isUndef() && N2.getOpcode() == ISD::EXTRACT_SUBVECTOR && | ||
N2.getOperand(1) == N3 && N2.getOperand(0).getValueType() == VT) | ||
return N2.getOperand(0); | ||
N2.getOperand(1) == N3 && N2.getOperand(0).getValueType() == VT) { | ||
if (N1.getOpcode() == ISD::POISON) | ||
return N2.getOperand(0); | ||
if (VT.isFixedLengthVector() && N2VT.isFixedLengthVector()) { | ||
unsigned LoBit = N3->getAsZExtVal(); | ||
unsigned HiBit = LoBit + N2VT.getVectorNumElements(); | ||
APInt EltMask = | ||
APInt::getBitsSet(VT.getVectorNumElements(), LoBit, HiBit); | ||
if (isGuaranteedNotToBePoison(N2.getOperand(0), ~EltMask)) | ||
return N2.getOperand(0); | ||
} else if (isGuaranteedNotToBePoison(N2.getOperand(0))) | ||
return N2.getOperand(0); | ||
} | ||
|
||
// If the inserted subvector is UNDEF, just use the input vector. | ||
// But not if skipping the insert could make the result more poisonous. | ||
if (N2.isUndef()) { | ||
if (VT.isFixedLengthVector()) { | ||
unsigned LoBit = N3->getAsZExtVal(); | ||
unsigned HiBit = LoBit + N2VT.getVectorNumElements(); | ||
APInt EltMask = | ||
APInt::getBitsSet(VT.getVectorNumElements(), LoBit, HiBit); | ||
if (isGuaranteedNotToBePoison(N1, EltMask)) | ||
return N1; | ||
} else if (isGuaranteedNotToBePoison(N1)) | ||
return N1; | ||
} | ||
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. again - are we doing too much in getNode at this stage? |
||
break; | ||
} | ||
case ISD::BITCAST: | ||
|
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.
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.
How many regressions do we get it we drop all this from getNode() and just leave the combine to do it?
We've often ended up doing more then basic canonicalisation in getNode() just to avoid one specific test regression.....
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.
We can remove the things releated to isGuaranteedNotToBePoison from INSERT_VECTOR_ELT and INSERT_SUBVECTOR in getNode without any diffs, if doing it after the changes I propose in "part 2" and "part 3". If doing it directly in this patch there is around 20 lit tests impacted.