diff options
author | Craig Topper <craig.topper@sifive.com> | 2022-02-10 21:33:08 -0800 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2022-02-15 03:02:27 -0800 |
commit | 3b544440f63157411d2bcf0e195329f7560a6991 (patch) | |
tree | ebe5e81e7fa9b8727a8cabb8bf448088530c9299 | |
parent | e22573ab7b2ddd24699f5e645562cf50f0858e33 (diff) | |
download | llvm-3b544440f63157411d2bcf0e195329f7560a6991.zip llvm-3b544440f63157411d2bcf0e195329f7560a6991.tar.gz llvm-3b544440f63157411d2bcf0e195329f7560a6991.tar.bz2 |
[RISCV] Insert VSETVLI at the end of a basic block if we didn't produce BlockInfo.Exit.
This is an alternative to D118667 that instead of fixing the store
to match phase 1, it tries to detect the mismatch with the expected
value at the end of the block. This inserts a vsetvli after the vse
to satisfy the requirement of the other basic block.
We still have serious design issues in the pass, that is going to
require some rethinking.
Differential Revision: https://reviews.llvm.org/D119518
(cherry picked from commit 541c9ba842256023611e5a6c5f01e01c40688044)
-rw-r--r-- | llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp | 15 | ||||
-rw-r--r-- | llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp index d39e080..6c4d268 100644 --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -334,6 +334,10 @@ public: return false; } + bool operator!=(const VSETVLIInfo &Other) const { + return !(*this == Other); + } + // Calculate the VSETVLIInfo visible to a block assuming this and Other are // both predecessors. VSETVLIInfo intersect(const VSETVLIInfo &Other) const { @@ -1096,6 +1100,17 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) { CurInfo = VSETVLIInfo::getUnknown(); PrevVSETVLIMI = nullptr; } + + // If we reach the end of the block and our current info doesn't match the + // expected info, insert a vsetvli to correct. + if (MI.isTerminator()) { + const VSETVLIInfo &ExitInfo = BlockInfo[MBB.getNumber()].Exit; + if (CurInfo.isValid() && ExitInfo.isValid() && !ExitInfo.isUnknown() && + CurInfo != ExitInfo) { + insertVSETVLI(MBB, MI, ExitInfo, CurInfo); + CurInfo = ExitInfo; + } + } } } diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir index c96c6e5..1cb4169 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir +++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir @@ -592,12 +592,10 @@ body: | ; CHECK-NEXT: [[PseudoVADD_VX_M1_:%[0-9]+]]:vr = PseudoVADD_VX_M1 [[PseudoVID_V_M1_]], [[PHI]], -1, 6, implicit $vl, implicit $vtype ; CHECK-NEXT: [[MUL:%[0-9]+]]:gpr = MUL [[PHI]], [[SRLI]] ; CHECK-NEXT: [[ADD:%[0-9]+]]:gpr = ADD [[COPY]], [[MUL]] - ; FIXME: We insert a SEW=32,LMUL=1/2 VSETVLI here but no SEW=64,LMUL=1 - ; VSETVLI before the VADD above. This misconfigures the VADD in the case that - ; the loop takes its backedge. ; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 87, implicit-def $vl, implicit-def $vtype, implicit $vl ; CHECK-NEXT: PseudoVSE32_V_MF2 killed [[PseudoVADD_VX_M1_]], killed [[ADD]], -1, 5, implicit $vl, implicit $vtype ; CHECK-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[PHI]], 1 + ; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 88, implicit-def $vl, implicit-def $vtype, implicit $vl ; CHECK-NEXT: BLTU [[ADDI]], [[COPY1]], %bb.1 ; CHECK-NEXT: PseudoBR %bb.2 ; CHECK-NEXT: {{ $}} |