Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -119,8 +119,13 @@ if (I != MBB.end()) DL = I->getDebugLoc(); - unsigned Opcode; + MachineFunction *MF = MBB.getParent(); + const MachineFrameInfo &MFI = MF->getFrameInfo(); + MachineMemOperand *MMO = MF->getMachineMemOperand( + MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOStore, + MFI.getObjectSize(FI), MFI.getObjectAlign(FI)); + unsigned Opcode; if (RISCV::GPRRegClass.hasSubClassEq(RC)) Opcode = TRI->getRegSizeInBits(RISCV::GPRRegClass) == 32 ? RISCV::SW : RISCV::SD; @@ -134,7 +139,8 @@ BuildMI(MBB, I, DL, get(Opcode)) .addReg(SrcReg, getKillRegState(IsKill)) .addFrameIndex(FI) - .addImm(0); + .addImm(0) + .addMemOperand(MMO); } void RISCVInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, @@ -146,8 +152,13 @@ if (I != MBB.end()) DL = I->getDebugLoc(); - unsigned Opcode; + MachineFunction *MF = MBB.getParent(); + const MachineFrameInfo &MFI = MF->getFrameInfo(); + MachineMemOperand *MMO = MF->getMachineMemOperand( + MachinePointerInfo::getFixedStack(*MF, FI), MachineMemOperand::MOLoad, + MFI.getObjectSize(FI), MFI.getObjectAlign(FI)); + unsigned Opcode; if (RISCV::GPRRegClass.hasSubClassEq(RC)) Opcode = TRI->getRegSizeInBits(RISCV::GPRRegClass) == 32 ? RISCV::LW : RISCV::LD; @@ -158,7 +169,10 @@ else llvm_unreachable("Can't load this register from stack slot"); - BuildMI(MBB, I, DL, get(Opcode), DstReg).addFrameIndex(FI).addImm(0); + BuildMI(MBB, I, DL, get(Opcode), DstReg) + .addFrameIndex(FI) + .addImm(0) + .addMemOperand(MMO); } void RISCVInstrInfo::movImm(MachineBasicBlock &MBB, Index: llvm/test/CodeGen/RISCV/select-optimize-multiple.ll =================================================================== --- llvm/test/CodeGen/RISCV/select-optimize-multiple.ll +++ llvm/test/CodeGen/RISCV/select-optimize-multiple.ll @@ -222,14 +222,13 @@ ; RV32I-NEXT: sw a4, 12(sp) ; RV32I-NEXT: fld ft0, 8(sp) ; RV32I-NEXT: sw a1, 8(sp) -; RV32I-NEXT: sw a2, 12(sp) -; RV32I-NEXT: fld ft1, 8(sp) ; RV32I-NEXT: andi a0, a0, 1 -; RV32I-NEXT: bnez a0, .LBB5_2 -; RV32I-NEXT: # %bb.1: # %entry -; RV32I-NEXT: fmv.d ft1, ft0 +; RV32I-NEXT: sw a2, 12(sp) +; RV32I-NEXT: beqz a0, .LBB5_2 +; RV32I-NEXT: # %bb.1: +; RV32I-NEXT: fld ft0, 8(sp) ; RV32I-NEXT: .LBB5_2: # %entry -; RV32I-NEXT: fsd ft1, 8(sp) +; RV32I-NEXT: fsd ft0, 8(sp) ; RV32I-NEXT: lw a0, 8(sp) ; RV32I-NEXT: lw a1, 12(sp) ; RV32I-NEXT: addi sp, sp, 16