This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Canonicalize AVL=setvli to AVL=Imm or AVL=VLMAX
ClosedPublic

Authored by reames on May 17 2022, 10:20 AM.

Details

Summary

This patch adds a transform to the local prepass in InsertVSETVLI which canonicalizes an AVL of a register from another vsetvli into immediate or VLMAX when VTYPE is the same. In this patch, I chose to be conservative and avoid arbitrary vreg forwarding due to profitability concerns about possibility overlapping live ranges.

This has the effect of eliminating vsetvli instructions in loops which are walking either VLMAX or a constant number of lanes per iteration.

Diff Detail

Event Timeline

reames created this revision.May 17 2022, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 10:20 AM
reames requested review of this revision.May 17 2022, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 10:20 AM
craig.topper added inline comments.May 17 2022, 10:58 AM
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
1255

Can this be hasSameVLMAX instead of hasSameVTYPE?

craig.topper added inline comments.
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
1255

Oh I guess that's what the TODO in the comment was. Is there any reason to not do that now?

reames added inline comments.May 17 2022, 11:05 AM
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
1255

Is HasSameVLMAX the same as "for all AVL, produce the same VL"?

It seems like maybe it is, but I hadn't fully recognized that if so. Probably needs a comment/name update.

reames added inline comments.May 17 2022, 11:11 AM
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
1255

If it is the same, I see at least three other places in code we can generalize. With your permission, I'll do that in a separate change.

craig.topper accepted this revision.May 17 2022, 11:23 AM

LGTM

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

The documentation for how VL is determined from AVL only mentions VLMAX. So I've been assuming that the calculation is independent of specific LMUL or SEW value and that only their relative ratio mattered.

We can do it separately.

This revision is now accepted and ready to land.May 17 2022, 11:23 AM
This revision was landed with ongoing or failed builds.May 17 2022, 11:46 AM
This revision was automatically updated to reflect the committed changes.