Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

rohitaggarwal007
Copy link
Contributor

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

Rohit Aggarwal and others added 27 commits April 9, 2025 14:27
… 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
…7/llvm-project into gatherMultipleOccurrence
@rohitaggarwal007
Copy link
Contributor Author

@RKSimon, This is the new PR as previous one got closed due to merge conflict(#134979 )

@RKSimon RKSimon self-requested a review April 30, 2025 21:26
Copy link
Collaborator

@RKSimon RKSimon left a 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();
Copy link
Collaborator

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

Copy link
Contributor Author

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 &&
Copy link
Collaborator

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

Copy link
Contributor Author

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);
// }
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Copy link
Contributor Author

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) {
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

github-actions bot commented May 5, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@RKSimon RKSimon left a 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)) {
Copy link
Collaborator

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)

Copy link
Contributor Author

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)

@rohitaggarwal007
Copy link
Contributor Author

@RKSimon Can you please merge my changes?
I don't have the write permission.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants