diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp index 3feb7ec347543..c40b9031543fe 100644 --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -1511,6 +1511,11 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) { return; } + // If the AVL isn't used in its predecessors then bail, since we have no AVL + // to insert a vsetvli with. + if (AvailableInfo.hasAVLIgnored()) + return; + // Model the effect of changing the input state of the block MBB to // AvailableInfo. We're looking for two issues here; one legality, // one profitability. diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir index 596ea1c39fcea..16c4a1a0a89ec 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir +++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir @@ -130,6 +130,10 @@ ret void } + define void @pre_undemanded_vl() { + ret void + } + declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) declare @llvm.riscv.vadd.nxv1i64.nxv1i64.i64(, , , i64) #1 @@ -1041,3 +1045,12 @@ body: | PseudoRET ... +--- +name: pre_undemanded_vl +body: | + bb.0: + PseudoBR %bb.1 + bb.1: + %x:gpr = PseudoVMV_X_S undef $noreg, 6 + PseudoBR %bb.1 +...