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 @@ -481,12 +481,9 @@ // FP will be used to restore the frame in the epilogue, so we need // another base register BP to record SP after re-alignment. SP will // track the current stack after allocating variable sized objects. - if (hasBP(MF)) { + if (hasBP(MF)) // move BP, SP - BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADDI), BPReg) - .addReg(SPReg) - .addImm(0); - } + TII->copyPhysReg(MBB, MBBI, DL, BPReg, SPReg, false); } } }