This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Match strided loads with reversed indexing sequences
ClosedPublic

Authored by reames on Aug 14 2023, 8:25 AM.

Details

Summary

This extends the concat_vector of loads to strided_load transform to handle reversed index pattern. The previous code expected indexing of the form (a0, a1+S, a2+S,...). However, we can also see indexing of the form (a1+S, a2+S, a3+S, .., aS). This form is a strided load starting at address aN + S*(n-1) with stride -S.

Note that this is also fixing what looks to be a bug in the memory location reasoning for forward strided case. A strided load with negative stride access eltsize bytes past base ptr, and then bytes *before* base ptr. (That is, the range should extend from before base ptr to after base ptr.)

Diff Detail

Unit TestsFailed

Event Timeline

reames created this revision.Aug 14 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2023, 8:25 AM
reames requested review of this revision.Aug 14 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
luke added a comment.Aug 15 2023, 3:08 AM

Makes sense to me

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

Can we do for (SDValue Op : N->ops()) instead to remove the need for the extra isSimple() and isNormalLoad() checks above?

12915

Just an idea, can we use one lambda and pass in a reverse iterator of the Ptrs vector?

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-strided-load-combine.ll
497

We can strike off this todo

reames added inline comments.Aug 22 2023, 7:40 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
12900

We can, but we still need the BaseLd and BaseLdVT variables. Given that, I didn't think folding only part of the checks into the loop was worthwhile.

12915

Not unless you know how to do a reverse enumerate with a "first element" check. We need the index check and the index + or - one bits. I played with this and it was the best variant I found.

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-strided-load-combine.ll
497

Good catch. I need to add this to my mental checklist, it's one of my regular oops.

reames updated this revision to Diff 552361.Aug 22 2023, 7:42 AM

Address review comment

luke accepted this revision.Aug 22 2023, 7:52 AM

LGTM

This revision is now accepted and ready to land.Aug 22 2023, 7:52 AM
This revision was landed with ongoing or failed builds.Aug 22 2023, 8:00 AM
This revision was automatically updated to reflect the committed changes.