Skip to content
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

[RISCV] Match constant indices of non-index type when forming strided ops #65777

Closed

Conversation

preames
Copy link
Collaborator

@preames preames commented Sep 8, 2023

When checking to see if our index expressions can be converted into strided operations, we previously gave up if the index type wasn't an exact match for the intptrty for the address. Per gep semantics, this mismatch implies a sext or trunc cast to the respective index type. For constants, go ahead and evaluate that cast instead of giving up.

Note that the motivation of this is mostly test cleanup. We canonicalize at IR such that the gep index will match the intptrty. This is mostly useful so that we can write both RV32 and RV64 tests from the same source. Its also helpful in preventing confusion - I've stumbled across this at least four times now and wasted time each one.

@preames preames requested a review from a team as a code owner September 8, 2023 16:46
@topperc
Copy link
Collaborator

topperc commented Sep 8, 2023

Does this allow a vector of i8 indices like <0, 128, 0, 128, 0, 128, 0, 128> to be considered a stride of 128?

I'm traveling today so cant easily check.

@preames
Copy link
Collaborator Author

preames commented Sep 8, 2023

Does this allow a vector of i8 indices like <0, 128, 0, 128, 0, 128, 0, 128> to be considered a stride of 128?

Yep, it gets this wrong. I'm going to add the reduced test case, and then rework the patch. Good catch.

When checking to see if our index expressions can be converted into strided operations, we previously gave up if the index type wasn't an exact match for the intptrty for the address.  Instead, we can ask known bits how many bits are needed, and proceed as long as the number of required bits fits in intptrty.

Note that the motivation of this is mostly test cleanup.  We canonicalize at IR such that the gep index will match the intptrty.  This is mostly useful so that we can write both RV32 and RV64 tests from the same source.  Its also helpful in preventing confusion - I've stumbled across this at least four times now and wasted time each one.

Interestingly, this does appear to catch some loop cases that O3 does not canonicalize.  I don't think the vectorizer is likely to emit indices narrower that intptr, but if another frontend did, this might pick them up.

This may also pick up some pass ordering problems, but that's a happy accident at best.
@preames preames force-pushed the riscv-gather-scatter-index-active-bits branch from 1b7ac58 to c03ef26 Compare September 11, 2023 16:13
@preames preames changed the title [RISCV] Match indices based on significant bits when forming strided ops [RISCV] Match constant indices of non-index type when forming strided ops Sep 11, 2023
@preames
Copy link
Collaborator Author

preames commented Sep 11, 2023

Pushed a much more restricted version which still covers my practical interest. Hopefully, this one is actually correct.

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

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

LGTM

// than the pointer type. Adding the stride later may not wrap correctly.
// Technically we could handle wider indices, but I don't expect that in
// practice.
// We need the number of significant bits to match the index type. IF it
Copy link
Collaborator

Choose a reason for hiding this comment

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

Capital F in IF

preames added a commit that referenced this pull request Sep 18, 2023
… ops (#65777)

When checking to see if our index expressions can be converted into strided
operations, we previously gave up if the index type wasn't an exact match for
the intptrty for the address. Per gep semantics, this mismatch implies a sext
or trunc cast to the respective index type. For constants, go ahead and
evaluate that cast instead of giving up.

Note that the motivation of this is mostly test cleanup. We canonicalize at IR
such that the gep index will match the intptrty. This is mostly useful so that
we can write both RV32 and RV64 tests from the same source. Its also helpful in
preventing confusion - I've stumbled across this at least four times now and
wasted time each one.

Note: The test change for scatters unit stride cases contains a minor
regression for rv32 and 64 bit indices.  This is an artifact of order in which
changes are landing.  This will be addressed in a near future change for all
configurations.
@preames
Copy link
Collaborator Author

preames commented Sep 18, 2023

Landed as 0722800

@preames preames closed this Sep 18, 2023
@preames preames deleted the riscv-gather-scatter-index-active-bits branch September 18, 2023 16:42
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
… ops (llvm#65777)

When checking to see if our index expressions can be converted into strided
operations, we previously gave up if the index type wasn't an exact match for
the intptrty for the address. Per gep semantics, this mismatch implies a sext
or trunc cast to the respective index type. For constants, go ahead and
evaluate that cast instead of giving up.

Note that the motivation of this is mostly test cleanup. We canonicalize at IR
such that the gep index will match the intptrty. This is mostly useful so that
we can write both RV32 and RV64 tests from the same source. Its also helpful in
preventing confusion - I've stumbled across this at least four times now and
wasted time each one.

Note: The test change for scatters unit stride cases contains a minor
regression for rv32 and 64 bit indices.  This is an artifact of order in which
changes are landing.  This will be addressed in a near future change for all
configurations.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
… ops (llvm#65777)

When checking to see if our index expressions can be converted into strided
operations, we previously gave up if the index type wasn't an exact match for
the intptrty for the address. Per gep semantics, this mismatch implies a sext
or trunc cast to the respective index type. For constants, go ahead and
evaluate that cast instead of giving up.

Note that the motivation of this is mostly test cleanup. We canonicalize at IR
such that the gep index will match the intptrty. This is mostly useful so that
we can write both RV32 and RV64 tests from the same source. Its also helpful in
preventing confusion - I've stumbled across this at least four times now and
wasted time each one.

Note: The test change for scatters unit stride cases contains a minor
regression for rv32 and 64 bit indices.  This is an artifact of order in which
changes are landing.  This will be addressed in a near future change for all
configurations.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
… ops (llvm#65777)

When checking to see if our index expressions can be converted into strided
operations, we previously gave up if the index type wasn't an exact match for
the intptrty for the address. Per gep semantics, this mismatch implies a sext
or trunc cast to the respective index type. For constants, go ahead and
evaluate that cast instead of giving up.

Note that the motivation of this is mostly test cleanup. We canonicalize at IR
such that the gep index will match the intptrty. This is mostly useful so that
we can write both RV32 and RV64 tests from the same source. Its also helpful in
preventing confusion - I've stumbled across this at least four times now and
wasted time each one.

Note: The test change for scatters unit stride cases contains a minor
regression for rv32 and 64 bit indices.  This is an artifact of order in which
changes are landing.  This will be addressed in a near future change for all
configurations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants