-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[X86][SelectionDAG] Fix the Gather's base and index by modifying the Scale value #137813
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
[X86][SelectionDAG] Fix the Gather's base and index by modifying the Scale value #137813
Conversation
… Node. Using the approach to update the Scale if SHL Opcode and followed by truncate.
… Node. Using the approach to update the Scale if SHL Opcode and followed by truncate.
…7/llvm-project into gatherMultipleOccurrence
…7/llvm-project into gatherMultipleOccurrence
…7/llvm-project into gatherMultipleOccurrence
…7/llvm-project into gatherMultipleOccurrence
…7/llvm-project into gatherMultipleOccurrence
…007/llvm-project into gatherMultipleOccurrence
… identify Signed bits.
…7/llvm-project into gatherMultipleOccurrence
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 - almost there!
DCI.AddToWorklist(N); | ||
return SDValue(N, 0); | ||
} | ||
uint64_t ScaleAmt = Scale->getAsZExtVal(); |
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.
move this up and reuse in Log2_32 check - we should probably assert that ScaleAmt is a power of 2 as well
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.
Done
} | ||
uint64_t ScaleAmt = Scale->getAsZExtVal(); | ||
if (auto MinShAmt = DAG.getValidMinimumShiftAmount(Index)) { | ||
if (*MinShAmt >= 1 && (*MinShAmt + Log2_64(ScaleAmt)) < 4 && |
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.
merge Log2_64 call with the existing Log2_32 call
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.
Done
unsigned IndexWidth = Index.getScalarValueSizeInBits(); | ||
|
||
// Shrink indices if they are larger than 32-bits. | ||
// Only do this before legalize types since v2i64 could become v2i32. | ||
// FIXME: We could check that the type is legal if we're after legalize | ||
// types, but then we would need to construct test cases where that happens. | ||
if (IndexWidth > 32 && DAG.ComputeNumSignBits(Index) > (IndexWidth - 32)) { | ||
unsigned ComputeNumSignBits = DAG.ComputeNumSignBits(Index); | ||
if (Index.getOpcode() == ISD::SHL) { |
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.
All this code needs moving inside the IndexWidth > 32 check - needs commenting as well
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.
Done
✅ With the latest revision this PR passed the C/C++ code formatter. |
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 with one minor
// Shrink indices if they are larger than 32-bits. | ||
// Only do this before legalize types since v2i64 could become v2i32. | ||
// FIXME: We could check that the type is legal if we're after legalize | ||
// types, but then we would need to construct test cases where that happens. | ||
if (IndexWidth > 32 && DAG.ComputeNumSignBits(Index) > (IndexWidth - 32)) { | ||
// \ComputeNumSignBits value is recomputed for the shift Index | ||
if (IndexWidth > 32 && ComputeNumSignBits > (IndexWidth - 32)) { |
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.
Probably better if you can move everything inside if (IndexWidth > 32)
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.
@RKSimon, Done. Moved the code inside the if (IndexWidth > 32)
@RKSimon Can you please merge my changes? Thanks |
// Attempt to move shifted index into the address scale, allows further | ||
// index truncation below. | ||
if (Index.getOpcode() == ISD::SHL && isa<ConstantSDNode>(Scale)) { | ||
unsigned BitWidth = Index.getScalarValueSizeInBits(); |
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.
Hoist the equivalent IndexWidth above this and remove BitWidth
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.
Sure
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.
Done
ComputeNumSignBits += *MinShAmt; | ||
} | ||
} | ||
} |
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 don't think we need this anymore
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.
@RKSimon, I do not understand the comment fully... Does it mean to move it outside IndexWith > 32 or Does it mean to remove this code snippet?
if (Index.getOpcode() == ISD::SHL) { if (auto MinShAmt = DAG.getValidMinimumShiftAmount(Index)) { if (DAG.ComputeNumSignBits(Index.getOperand(0)) > 1) { ComputeNumSignBits += *MinShAmt; } } }
We can not remove this code as it is required and our test case is failing.
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.
In which case, please can you pull it out of this patch - I'm happy with the rest of it, but I'm concerned that this will only work under very specific conditions - better to pull it out and you can work on it in a follow up PR.
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.
Incase of SHL have the value of shift 4 or greater... We are recalculating the number of signed bit so that we can truncate.
Sure, i will create a separate PR for this
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.
Done, removed the code and created a separate PR.
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 - cheers
@RKSimon, Can you please merge this on my behalf? Thanks |
…39703) Fix the Gather's Index for SHL Opcode in which shift amount is 4 or greater. It is in the continuity of #137813 --------- Co-authored-by: Rohit Aggarwal <[email protected]> Co-authored-by: Simon Pilgrim <[email protected]>
…vm#139703) Fix the Gather's Index for SHL Opcode in which shift amount is 4 or greater. It is in the continuity of llvm#137813 --------- Co-authored-by: Rohit Aggarwal <[email protected]> Co-authored-by: Simon Pilgrim <[email protected]>
…vm#139703) Fix the Gather's Index for SHL Opcode in which shift amount is 4 or greater. It is in the continuity of llvm#137813 --------- Co-authored-by: Rohit Aggarwal <[email protected]> Co-authored-by: Simon Pilgrim <[email protected]>
Fix the Gather's base and index for one use or multiple uses of Index Node. Using the approach to update the Scale if SHL Opcode and followed by truncate.
PR closed : #134979