This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix missing vsetvli in transparent block case
ClosedPublic

Authored by reames on May 16 2022, 10:16 AM.

Details

Summary

We've got a lurking problem with our data flow implementation where different phases disagree, resulting in possible miscompiles. D119518 introduced a workaround, but failed to consider blocks which only contain load/stores compatible with their incoming state.

When I went to rebase and simplify D125232, it turned out that not all of the correctness issues had been fixed yet after all. This is the correctness fix accidentally embedded in the original more complicated version.

Note that the test changes here are mostly regressions. It's worth noting that the simplified version of D125232 exactly reverses all the non-functional diffs in the test caused here. I expect to land them both close in time.

Diff Detail

Event Timeline

reames created this revision.May 16 2022, 10:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 10:16 AM
reames requested review of this revision.May 16 2022, 10:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 10:16 AM
craig.topper added inline comments.May 16 2022, 10:45 AM
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
1124–1125

Use CurInfo in the assert?

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
30

Does this mean that ExitInfo and CurInfo don't match at the end? Why did that occur? There's nothing that has any special cases in this function.

Is it because of the AVL being from a vsetvli?

reames updated this revision to Diff 429779.May 16 2022, 10:48 AM

Address review comment

reames marked an inline comment as done.May 16 2022, 10:51 AM
reames added inline comments.
llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
30

It's because the AVL on the abstract state is technically not equal. They both represent the same runtime value, but the first state has an AVL of a0, the vfsub produces one with an AVL of x0 (vlmax). This is due to my recently introduce prepass which creates this canonicalization.

We could pretty easily fix this with a minor improvement to insertVSETVLI, but given the following patch immediately reverses this, I left it to avoid complicating the patch series further. :)

reames added inline comments.May 16 2022, 1:36 PM
llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
30

Slight correction here. The final state after the vfsub has an AVL produced by the first instruction (not vlmax as I said before.) The difference between stage 1/2 and 3 is that having the prior state lets us realize that is compatible (e.g. same bits in registers). We then emit the end of block check to bring the abstract state back in sync.

This hints we could reuse needVSETVLI in the compensation check, but since the compensation code is about to disappear, I don't know this is worth doing.

craig.topper accepted this revision.May 16 2022, 1:39 PM

LGTM

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
30

Makes sense. Thanks for the explanation.

This revision is now accepted and ready to land.May 16 2022, 1:39 PM
This revision was landed with ongoing or failed builds.May 16 2022, 5:06 PM
This revision was automatically updated to reflect the committed changes.