mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-05 08:58:30 +00:00
[riscv] Fix state tracking bug on vsetvli (phi of vsetvli) peephole
This fixes the first of several cases where the state computed in phase 1 and 2 of the algorithm differs from the state computed during phase 3. Note that such differences can cause miscompiles by creating disagreements about contents of the VL and VTYPE registers at block boundaries. In this particular case, we recognize that for the first vsetvli in a block, that if the AVL is a phi of GPR results from previous vsetvlis and the VTYPE field matches, we can avoid emitting a vsetvli as the register contents don't change. Unfortunately, the abstract state does change and that update was lost. As noted in the test change, this can actually improve results by preserving information until later state transitions in the block. However, this minor codegen improvement is not the motivation for the patch. The motivation is to avoid cases a case where we break a key internal correctness invariant. Differential Revision: https://reviews.llvm.org/D125133
This commit is contained in:
parent
bc150a07f1
commit
7ed16e7c51
@ -1124,9 +1124,16 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
|
||||
// use the predecessor information.
|
||||
assert(BlockInfo[MBB.getNumber()].Pred.isValid() &&
|
||||
"Expected a valid predecessor state.");
|
||||
if (needVSETVLI(NewInfo, BlockInfo[MBB.getNumber()].Pred) &&
|
||||
needVSETVLIPHI(NewInfo, MBB)) {
|
||||
insertVSETVLI(MBB, MI, NewInfo, BlockInfo[MBB.getNumber()].Pred);
|
||||
if (needVSETVLI(NewInfo, BlockInfo[MBB.getNumber()].Pred)) {
|
||||
// If this is the first implicit state change, and the state change
|
||||
// requested can be proven to produce the same register contents, we
|
||||
// can skip emitting the actual state change and continue as if we
|
||||
// had since we know the GPR result of the implicit state change
|
||||
// wouldn't be used and VL/VTYPE registers are correct. Note that
|
||||
// we *do* need to model the state as if it changed as while the
|
||||
// register contents are unchanged, the abstract model can change.
|
||||
if (needVSETVLIPHI(NewInfo, MBB))
|
||||
insertVSETVLI(MBB, MI, NewInfo, BlockInfo[MBB.getNumber()].Pred);
|
||||
CurInfo = NewInfo;
|
||||
}
|
||||
} else {
|
||||
|
@ -453,7 +453,7 @@ define void @saxpy_vec(i64 %n, float %a, float* nocapture readonly %x, float* no
|
||||
; CHECK-NEXT: vle32.v v16, (a2)
|
||||
; CHECK-NEXT: slli a4, a3, 2
|
||||
; CHECK-NEXT: add a1, a1, a4
|
||||
; CHECK-NEXT: vsetvli zero, a3, e32, m8, tu, mu
|
||||
; CHECK-NEXT: vsetvli zero, zero, e32, m8, tu, mu
|
||||
; CHECK-NEXT: vfmacc.vf v16, fa0, v8
|
||||
; CHECK-NEXT: vse32.v v16, (a2)
|
||||
; CHECK-NEXT: sub a0, a0, a3
|
||||
|
Loading…
x
Reference in New Issue
Block a user