This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][InsertVSETVLI] Support constant VLs larger than immediate encoding
ClosedPublic

Authored by reames on May 23 2023, 7:16 AM.

Details

Summary

The immediate field on the vsetivli is fairly limited. For larger vectors, we end up having to materialize a constant in a register. We hadn't plumbed the infrastructure to treat such materialized constants as constants for purpose of vsetvli elimination.

I only bothered to handle LI. We could extend this to LUI sequences, but well, 2048 elements is probably enough for all practical fixed length vector codegen. :)

The test delta does point out a related problem. At LMUL8, we see increased register allocation pressure, and we should probably either a) address register allocation remat, or b) be less aggressive about eliminating vsetvlis at high lmul. Note that high LMUL code is not generated much by default.

Diff Detail

Event Timeline

reames created this revision.May 23 2023, 7:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 7:16 AM
reames requested review of this revision.May 23 2023, 7:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 7:16 AM
luke added a comment.May 23 2023, 8:42 AM

Makes sense to me. As you say LMUL=8 is pretty rare, and in those cases I presume we would want to be using scalable vectors anyway

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
375

Duplicate ;

craig.topper added inline comments.May 23 2023, 9:56 AM
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
12509–12510

Is this instruction dead? Do we need to try to delete these li instructions or run DCE after vsetvli?

reames updated this revision to Diff 525237.May 24 2023, 10:03 AM

Address style comment

reames added inline comments.May 24 2023, 10:04 AM
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
12509–12510

It looks like it yes. We already kill other vsetvlis with register VLs, so it's possible we can already see this elsewhere. Note sure about that to be honest; I can't quickly come up with a test case where we would.

If you okay with it, I'd like to address this in a following patch.

craig.topper accepted this revision.May 24 2023, 10:09 AM

LGTM

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
12509–12510

We can address it as a follow up.

This revision is now accepted and ready to land.May 24 2023, 10:09 AM
This revision was landed with ongoing or failed builds.May 24 2023, 10:38 AM
This revision was automatically updated to reflect the committed changes.