-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
base: main
Are you sure you want to change the base?
[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
// if (TLI.SimplifyDemandedBits(Index, DemandedBits, DCI)) { | ||
// return SDValue(N, 0); | ||
// } | ||
// } |
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.
remove 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
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 |
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