From dcdb0bf25bc83e4ae4e7da87311dd93030e9c9ce Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Thu, 2 Jun 2022 07:56:06 -0700 Subject: [PATCH] [RISCV] Fix an inconsistency with compatible load/store handling Once we've computed the incoming predecessor state, we should use the same compatibility check with knowledge of MI as we did in phase 2 in order to be consistent across all phases. Differential Revision: https://reviews.llvm.org/D126574 --- llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp | 2 +- .../RISCV/rvv/vsetvli-insert-crossbb.ll | 29 +++++++++++++++++-- .../RISCV/rvv/vsetvli-insert-crossbb.mir | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp index f3a22852c742..30659797531c 100644 --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -1123,7 +1123,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) { // use the predecessor information. CurInfo = BlockInfo[MBB.getNumber()].Pred; assert(CurInfo.isValid() && "Expected a valid predecessor state."); - if (needVSETVLI(NewInfo, CurInfo)) { + if (needVSETVLI(MI, NewInfo, CurInfo)) { // 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 diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll index ce8eabdfb418..2b789a177da3 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll @@ -505,8 +505,8 @@ define @test_vsetvli_x0_x0(* %x, @test_vsetvli_x0_x0_2(* %x, %b } +define @compat_store_consistency(i1 %cond, %a, %b, * %p1, %c, * %p2) { +; CHECK-LABEL: compat_store_consistency: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: andi a0, a0, 1 +; CHECK-NEXT: vsetvli a3, zero, e64, m1, ta, mu +; CHECK-NEXT: vfadd.vv v8, v8, v9 +; CHECK-NEXT: vs1r.v v8, (a1) +; CHECK-NEXT: beqz a0, .LBB19_2 +; CHECK-NEXT: # %bb.1: # %if.then +; CHECK-NEXT: vse32.v v10, (a2) +; CHECK-NEXT: .LBB19_2: # %if.end +; CHECK-NEXT: ret +entry: + %res = fadd %a, %b + store %res, * %p1 + br i1 %cond, label %if.then, label %if.end + +if.then: ; preds = %entry + store %c, * %p2 + br label %if.end + +if.end: ; preds = %if.else, %if.then + ret %res +} + declare i64 @llvm.riscv.vsetvlimax.i64(i64, i64) declare @llvm.riscv.vle.nxv1f64.i64(, * nocapture, i64) declare @llvm.riscv.vfadd.nxv1f64.nxv1f64.i64(, , , i64) diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir index 2d57de1e44f1..d53b1b8bf430 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir +++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir @@ -941,8 +941,8 @@ body: | ; CHECK-NEXT: successors: %bb.3(0x80000000) ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: [[ADD1:%[0-9]+]]:gpr = ADD %src, [[PHI]] - ; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 69 /* e8, mf8, ta, mu */, implicit-def $vl, implicit-def $vtype, implicit $vl ; CHECK-NEXT: [[PseudoVLE8_V_MF8_:%[0-9]+]]:vrnov0 = PseudoVLE8_V_MF8 killed [[ADD1]], -1, 3 /* e8 */, implicit $vl, implicit $vtype + ; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 69 /* e8, mf8, ta, mu */, implicit-def $vl, implicit-def $vtype, implicit $vl ; CHECK-NEXT: [[PseudoVADD_VI_MF8_:%[0-9]+]]:vrnov0 = PseudoVADD_VI_MF8 [[PseudoVLE8_V_MF8_]], 4, -1, 3 /* e8 */, implicit $vl, implicit $vtype ; CHECK-NEXT: [[ADD2:%[0-9]+]]:gpr = ADD %dst, [[PHI]] ; CHECK-NEXT: PseudoVSE8_V_MF8 killed [[PseudoVADD_VI_MF8_]], killed [[ADD2]], -1, 3 /* e8 */, implicit $vl, implicit $vtype