This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support interleaved load lowering
Needs ReviewPublic

Authored by luke957 on Jul 30 2021, 8:57 PM.

Details

Summary

Lower interleaved load to segment load intrinsic.

Diff Detail

Event Timeline

luke957 created this revision.Jul 30 2021, 8:57 PM
luke957 requested review of this revision.Jul 30 2021, 8:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2021, 8:57 PM

Don't you need to add the InterleavedAccess pass to RISCVTargetMachine?

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1231

These intrinsics only have SelectionDAG support for scalable vector types. And they take VL as an operand.

luke957 edited the summary of this revision. (Show Details)Aug 11 2021, 4:41 AM
luke957 added reviewers: craig.topper, frasercrmck.

Don't you need to add the InterleavedAccess pass to RISCVTargetMachine?

Yeah, we need to do this. I have updated the pacth.

craig.topper added inline comments.Aug 18 2021, 9:01 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1289

Please address these clang-format warnings

craig.topper added inline comments.Aug 18 2021, 9:02 PM
llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
6

Why are we only testing one factor?

luke957 added inline comments.Aug 28 2021, 8:44 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1289

Fix format.

llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
6

Add test case for factor 3 and 4.

craig.topper added inline comments.Sep 7 2021, 9:53 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1201

Does this need to check if floating point elements are supported?

1225

Please fix this clang-tidy warning

1227

This is not the correct way to convert a fixed vector type to a scalable vector type. For large vectors this will create a type that maps to something larger than LMUL=8. We need to map fixed vector types to scalable vector types using the logic from RISCVTargetLowering::getContainerForFixedLengthVector which takes into account a user provided VLEN via -riscv-v-vector-bits-min command line option.

llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
9

Why is the VL 1? The vector type has 16 elements, the interleave factor is 2. So the VL should be 8.

craig.topper added inline comments.Sep 7 2021, 9:55 AM
llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
18

Please make sure the tests can't be optimized to nothing. These shuffles aren't used so are allowed to be deleted.

luke957 updated this revision to Diff 375460.Sep 27 2021, 8:08 PM

Clang tidy

luke957 added inline comments.Sep 27 2021, 9:57 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1201

Em, is it enough to check bit size only? I think floating point elements will not produce new bit size.

1225

Sorry, I should clang tidy every diff before uploading.

1227

Em, I'm a little confused here. I understand RISCVTargetLowering::getContainerForFixedLengthVector is used in backend when SDAG is built as this method operates on MVT types. So if we just use opt in the middle-end, is this still needed? Further more, if something larger than LMUL=8 appears, could it be legalized by the backend?

llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
9

Fix this. It's my mistake.

18

Could we guarantee this by carefully using the RUN instructions in the beginning of the test case?

craig.topper added inline comments.Sep 27 2021, 10:19 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1201

You're creating a target specific intrinsic, like Intrinsic::riscv_vlseg2. If the floating point type isn't legal, the backend will error when trying to select the intrinsic. If its not legal and this code doesn't touch it, then the backend will be able to scalarize the loads and shuffles.

1227

All conversions from a fixed vector type to a scalable vector must follow the VLEN passed on the command line in -riscv-v-vector-bits-min. The backend should not be splitting a scalable type if the fixed vector type was supposed to be legal type.

llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
18

Technically yes, but I wanted to see how this codegened in SelectionDAG and everything got deleted. So I'd rather have a more robust test.

luke957 added inline comments.Oct 26 2021, 12:23 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1201

Thanks. I understand.

1227

Yeah, you are right. It takes me some time to understand that. I think we need to make sure the target specific intrinsic is legal according to the VLEN passed on the command line in -riscv-v-vector-bits-min, so either fixed length vector or scalable vector need legality check (or conversion) for they might exceed the limit of max(LMUL)==8. It seems to be a little bit complicated. Or maybe we could fix this in another patch?

llvm/test/Transforms/InterleavedAccess/RISCV/interleaved-accesses.ll
18

I understand. Address comment.

Gently ping.

craig.topper added inline comments.Nov 8 2021, 7:39 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1227

This needs to be handled in this patch. I don't want to think through issues that can arise by not honoring the VLEN correctly.

It might be easier to add fixed vector instrinsics for segment load/store and handle the conversion from fixed vector to scalable vector inside of SelectionDAG where we already have helper functions for the conversion. This is what I did for the RISCVGatherScatterLowering pass which uses masked_strided_load and masked_strided_store intrinsics.

luke957 updated this revision to Diff 419177.Mar 30 2022, 9:13 AM
rebase and update