This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach vsetvli insertion to not insert redundant vsetvli right after VLEFF/VLSEGFF.
ClosedPublic

Authored by fakepaper56 on Jun 11 2022, 12:48 PM.

Details

Summary

VSETVLIInfos right after VLEFF/VLSEGFF are currently unknown since they modify
VL. Unknown VSETVLIInfos make next vector operations needed to be inserted
VSET(I)VLI. Actually the next vector operation of VLEFF/VLSEGFF may not need to
be inserted VSET(I)VLI if it uses same VTYPE and the resulted vl of
VLEFF/VLSEGFF.

Take the below C code as an example,

vint8m4_t vec_src1 = vle8ff_v_i8m4(str1, &new_vl, vl);
vbool2_t mask1 = vmseq_vx_i8m4_b2(vec_src1, 0, new_vl);
vsetvli insertion adds a redundant vsetvli for that,

Assembly result:

vsetvli a2,a2,e8,m4,ta,mu
vle8ff.v v28,(a0)
csrr a3,vl ; redundant
vsetvli zero,a3,e8,m4,ta,mu ; redundant
vmseq.vi v25,v28,0

After D126794, VLEFF/VLSEGFF has a define having value of VL. The patch consider
there is a ghost vsetvli right after VLEFF/VLSEGFF. The ghost VSET(I)LIs use the
vl output of the VLEFF/VLSEGFF as its AVL and same VTYPE of the VLEFF/VLSEGFF.
The ghost vsetvli must be redundant, and we could use it to get the VSETVLIInfo
right after VLEFF/VLSEGFF.

Diff Detail

Event Timeline

fakepaper56 created this revision.Jun 11 2022, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2022, 12:48 PM
fakepaper56 requested review of this revision.Jun 11 2022, 12:48 PM

Refine the commit message.

fakepaper56 edited the summary of this revision. (Show Details)Jun 11 2022, 12:53 PM
craig.topper added inline comments.Jun 12 2022, 7:38 PM
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
934

Please rebase now that isFaultFirstLoad isn't in RISCVInstrInfo.

1085

Can we split this if and combine it with the one below? By doing something like

if (!DefMI)
  return true;

if (isVectorConfigInstr(*DefMI)) {
  DefInfo = getInfoForVSETVLI(*DefMI);
} else if (TII->isFaultFirstLoad(*DefMI)) {
  DefInfo = computeInfoForInstr(*DefMI, DefMI->getDesc().TSFlags, MRI);
  DefInfo.setAVLReg(DefMI->getOperand(1).getReg());
} else {
  return true;
}

Along with appropriate modifications to the comments.

1149–1150

This code is identical to the code on line 975, except for which varaible we update. Could this use a shared function?

Address Craig's comments.

  1. Add function updateToEndStatus to share code for updating VSETVLIInfo. Does somebody have better naming to represent the status between one MI and the next one?
  2. Refine code of needVSETVLIPHI.
fakepaper56 marked 2 inline comments as done.Jun 13 2022, 1:03 AM
fakepaper56 added inline comments.
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
934

Done.

1085

Done.

fakepaper56 marked 2 inline comments as done.

Refine the comments.

reames requested changes to this revision.Jun 13 2022, 8:05 AM

Three high level concerns with this patch.

First, you need to rework the patch description. As written, it sounds like you're trying to fix a functional issue. To the best of my knowledge, that does not appear to actually be the case. Instead, this patch is improving precision for the case where VL is modified by a FF instruction.

Second, this change mixes at least three separate optimizations. I've tagged everything which isn't the transfer rule, please remove them from the initial patch.

Third, we have three places which check for modifiesRegister(VL). You only update two of them. Make sure you include the third.

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

This should not be a member function on VSETVLIInfo. Its part of the data flow transfer rule, not the abstract state.

934

This is a separate optimization, move it to its own review.

1087

This is a separate optimization, move it to its own review.

This revision now requires changes to proceed.Jun 13 2022, 8:05 AM

Address reames's comments.

fakepaper56 retitled this revision from [RISCV] Teach vsetvli insertion to handle VLEFF/VLSEGFF. to [RISCV] Teach vsetvli insertion to not insert redundant vsetvli right after VLEFF/VLSEGFF..Jun 14 2022, 12:53 AM
fakepaper56 edited the summary of this revision. (Show Details)
fakepaper56 edited the summary of this revision. (Show Details)

Refine commit summary.

fakepaper56 edited the summary of this revision. (Show Details)Jun 14 2022, 12:59 AM
fakepaper56 marked 3 inline comments as done.Jun 14 2022, 1:55 AM
fakepaper56 added inline comments.
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
327

Done.

934

Done. And sorry the code is redundant.

1087

Done.

reames accepted this revision.Jun 14 2022, 7:50 AM

LGTM w/required change.

llvm/test/CodeGen/RISCV/rvv/vsetvli-modify-vl.ll
1 ↗(On Diff #436686)

It's not clear to me what this test is covering that the one above doesn't. It appears to be the same except for an extract vmseq? You might consider dropping it entirely.

Either way, it shouldn't be it's own file. Add to the end of vsetvli-insert.ll with a refined name please.

This revision is now accepted and ready to land.Jun 14 2022, 7:50 AM
fakepaper56 marked 3 inline comments as done.

Rebase to origin/main and move the new test case into vsetvli-insert.ll.

This revision was landed with ongoing or failed builds.Jun 14 2022, 10:58 PM
This revision was automatically updated to reflect the committed changes.