[RISCV] Fix missing cross-block VSETVLI insertion
authorFraser Cormack <fraser@codeplay.com>
Thu, 21 Oct 2021 14:32:12 +0000 (15:32 +0100)
committerFraser Cormack <fraser@codeplay.com>
Fri, 22 Oct 2021 09:45:10 +0000 (10:45 +0100)
commit74c6895b39e37b8d82993f862fe6c943da45962b
treea415b18dc6f839ceb46f3e5e2e4ca8cdd6178a49
parente5b87fb7222c0f16ca52c6e72540ed24c204638a
[RISCV] Fix missing cross-block VSETVLI insertion

This patch fixes a codegen bug, the test for which was introduced in
D112223.

When merging VSETVLIInfo across blocks, if the 'exit' VSETVLIInfo
produced by a block is found to be compatible with the VSETVLIInfo
computed as the intersection of the 'exit' VSETVLIInfo produced by the
block's predecessors, that blocks' 'exit' info is discarded and the
intersected value is taken in its place.

However, we have one authority on what constitutes VSETVLIInfo
compatibility and we are using it in two different contexts.

Compatibility is used in one context to elide VSETVLIs between
straight-line vector instructions. But compatibility when evaluated
between two blocks' exit infos ignores any info produced *inside* each
respective block before the exit points. As such it does not guarantee
that a block will not produce a VSETVLI which is incompatible with the
'previous' block.

As such, we must ensure that any merging of VSETVLIInfo is performed
using some notion of "strict" compatibility. I've defined this as a full
vtype match, but this is perhaps too pessimistic. Given that test
coverage in this regard is lacking -- the only change is in the failing
test -- I think this is a good starting point.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D112228
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir