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] Lower constant build_vectors with few non-sign bits via vsext #65648

Merged

Conversation

preames
Copy link
Collaborator

@preames preames commented Sep 7, 2023

If we have a build_vector such as [i64 0, i64 3, i64 1, i64 2], we instead lower this as vsext([i8 0, i8 3, i8 1, i8 2]). For vectors with 4 or fewer elements, the resulting narrow vector can be generated via scalar materialization.

For shuffles which get lowered to vrgathers, constant build_vectors of small constants are idiomatic. As such, this change covers all shuffles with an output type of 4 or less.

I deliberately started narrow here. I think it makes sense to expand this to longer vectors, but we need a more robust profit model on the recursive expansion. It's questionable if we want to do the zsext if we're going to generate a constant pool load for the narrower type anyways.

One possibility for future exploration is to allow the narrower VT to be less than 8 bits. We can't use vsext for that, but we could use something analogous to our widening interleave lowering with some extra shifts and ands.

@preames preames requested a review from a team as a code owner September 7, 2023 17:36
@topperc
Copy link
Collaborator

topperc commented Sep 7, 2023

I'm not sure what ZSEXT in the title is supposed to mean if we only consider SEXT?

@preames
Copy link
Collaborator Author

preames commented Sep 7, 2023

I'm not sure what ZSEXT in the title is supposed to mean if we only consider SEXT?

I'd meant that to be VSEXT. As in, the instruction. Will fix the typo.

@preames preames changed the title [RISCV] Lower constant build_vectors with few non-sign bits via ZSEXT [RISCV] Lower constant build_vectors with few non-sign bits via vsext Sep 7, 2023
@@ -3456,6 +3456,27 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
if (SDValue Res = lowerBuildVectorViaDominantValues(Op, DAG, Subtarget))
return Res;

// IF the number of signbits allows, see if we can lower as a <N x i8>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the capitalization of 'F' in 'If' intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, fixed.

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

If we have a build_vector such as [i64 0, i64 3, i64 1, i64 2], we instead lower this as vsext([i8 0, i8 3, i8 1, i8 2]).  For vectors with 4 or fewer elements, the resulting narrow vector can be generated via scalar materialization.

For shuffles which get lowered to vrgathers, constant build_vectors of small constants are idiomatic.  As such, this change covers all shuffles with an output type of 4 or less.

I deliberately started narrow here.  I think it makes sense to expand this to longer vectors, but we need a more robust profit model on the recursive expansion.  It's questionable if we want to do the zsext if we're going to generate a constant pool load for the narrower type anyways.

One possibility for future exploration is to allow the narrower VT to be less than 8 bits.  We can't use vsext for that, but we could use something analogous to our widening interleave lowering with some extra shifts and ands.
@preames preames force-pushed the pr-20230907-riscv-constant-build-vector-4x-sext branch from 1b54578 to 105311b Compare September 7, 2023 22:59
@preames preames merged commit b4a99f1 into llvm:main Sep 7, 2023
1 of 2 checks passed
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