diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -956,7 +956,27 @@ // D103622. // // Refer to https://github.com/llvm/llvm-project/issues/53016. - return MF.getSubtarget().hasVInstructions(); + + // Won't have RVV frame object without V/Zve* extensions. + if (!MF.getSubtarget().hasVInstructions()) + return false; + + // If there is scalable vector, there must be RVV frame object. + const MachineFrameInfo &MFI = MF.getFrameInfo(); + for (int I = 0, E = MFI.getObjectIndexEnd(); I != E; ++I) + if (MFI.getStackID(I) == TargetStackID::ScalableVector) + return true; + + // If there is any RVV instruction in the function, there might be RVV frame + // object. + for (const auto &MBB : MF) + for (const auto &MI : MBB) + for (const auto &MO : MI.uses()) + if (MO.isReg() && MO.getReg() == RISCV::VL) + return true; + + // Otherwise, there should not be any RVV frame object. + return false; } // Not preserve stack space within prologue for outgoing variables when the