This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Make use of SHXADD instructions in RVV spill/reload code.
ClosedPublic

Authored by craig.topper on May 2 2022, 11:32 PM.

Details

Summary

We can use SH1ADD, SH2ADD, SH3ADD to multipy by 3, 5, and 9 respectively.

We could extend this to 3, 5, or 9 multiplied by a power 2 by also
emitting a SLLI.

While there remove the code that looks up TII. We're already a
member of RISCV's TII.

Diff Detail

Event Timeline

craig.topper created this revision.May 2 2022, 11:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 11:32 PM
craig.topper requested review of this revision.May 2 2022, 11:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 11:32 PM
reames accepted this revision.May 3 2022, 1:07 PM

LGTM w/minor comments.

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1765

Can you commit this separately as a cleanup please?

1822

Aside: Shouldn't this simply be one of options inside movImm?

This revision is now accepted and ready to land.May 3 2022, 1:07 PM
craig.topper added inline comments.May 3 2022, 1:48 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1822

That's a good point. movImm probably handles this correctly.

craig.topper added inline comments.May 3 2022, 1:53 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1760

I'm considering merging this with it's one caller. There might be some more optimization opportunities if we include the ADD/SUB to SP.

For example, vlenb * 7 + sp could become

csrrd a0, vlenb
sub sp, sp, a0
slli a0, a0, 3
add sp, sp, a0

instead of

csrrd a0, vlenb
slli a1, a0, 3
sub a0, a1, a0
add sp, sp, a0

That would save a temporary register.

reames added inline comments.May 3 2022, 1:59 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1760

Separate commit please. :)

Any chance this could be done in a post-process combine like thing? Duplicating what appears to be generic multiple improvements seems like poor code structure.

craig.topper added inline comments.May 3 2022, 2:36 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
1760

Yes separate commit.

I'm not sure if we could do it in a generic combine. This code runs after register allocation and needs to scavenge a free register. An emergency spill will happen if it can't find one. Avoiding emergency spills would be one of the benefits of saving the use of a temporary register. If did a generic combine later we'd also have to remove the emergency spill.

1765

Will do

This revision was landed with ongoing or failed builds.May 3 2022, 7:41 PM
This revision was automatically updated to reflect the committed changes.