diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.h b/llvm/lib/Target/RISCV/RISCVInstrInfo.h --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.h +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.h @@ -49,10 +49,10 @@ MCInst getNop() const override; const MCInstrDesc &getBrCond(RISCVCC::CondCode CC) const; - unsigned isLoadFromStackSlot(const MachineInstr &MI, - int &FrameIndex) const override; - unsigned isStoreToStackSlot(const MachineInstr &MI, - int &FrameIndex) const override; + unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex, + unsigned &MemBytes) const override; + unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex, + unsigned &MemBytes) const override; void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg, diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -78,20 +78,28 @@ } unsigned RISCVInstrInfo::isLoadFromStackSlot(const MachineInstr &MI, - int &FrameIndex) const { + int &FrameIndex, + unsigned &MemBytes) const { switch (MI.getOpcode()) { default: return 0; case RISCV::LB: case RISCV::LBU: + MemBytes = 1; + break; case RISCV::LH: case RISCV::LHU: case RISCV::FLH: + MemBytes = 2; + break; case RISCV::LW: case RISCV::FLW: case RISCV::LWU: + MemBytes = 4; + break; case RISCV::LD: case RISCV::FLD: + MemBytes = 8; break; } @@ -105,17 +113,25 @@ } unsigned RISCVInstrInfo::isStoreToStackSlot(const MachineInstr &MI, - int &FrameIndex) const { + int &FrameIndex, + unsigned &MemBytes) const { switch (MI.getOpcode()) { default: return 0; case RISCV::SB: + MemBytes = 1; + break; case RISCV::SH: - case RISCV::SW: case RISCV::FSH: + MemBytes = 2; + break; + case RISCV::SW: case RISCV::FSW: + MemBytes = 4; + break; case RISCV::SD: case RISCV::FSD: + MemBytes = 8; break; } diff --git a/llvm/test/CodeGen/RISCV/stack-slot-coloring.mir b/llvm/test/CodeGen/RISCV/stack-slot-coloring.mir --- a/llvm/test/CodeGen/RISCV/stack-slot-coloring.mir +++ b/llvm/test/CodeGen/RISCV/stack-slot-coloring.mir @@ -94,10 +94,14 @@ ; CHECK-NEXT: $x27 = LW %stack.0.a, 0 :: (volatile dereferenceable load (s32) from %ir.a) ; CHECK-NEXT: renamable $x1 = LW %stack.0.a, 0 :: (volatile dereferenceable load (s32) from %ir.a) ; CHECK-NEXT: SW killed renamable $x1, %stack.1, 0 :: (store (s32) into %stack.1) + ; CHECK-NEXT: renamable $x1 = LB %stack.0.a, 0 :: (volatile dereferenceable load (s8) from %ir.a) + ; CHECK-NEXT: SW killed renamable $x1, %stack.0.a, 0 :: (volatile store (s32) into %ir.a) ; CHECK-NEXT: renamable $x1 = LW %stack.1, 0 :: (load (s32) from %stack.1) ; CHECK-NEXT: SW killed renamable $x1, %stack.0.a, 0 :: (volatile store (s32) into %ir.a) ; CHECK-NEXT: renamable $x1 = LW %stack.0.a, 0 :: (volatile dereferenceable load (s32) from %ir.a) ; CHECK-NEXT: SW killed renamable $x1, %stack.1, 0 :: (store (s32) into %stack.1) + ; CHECK-NEXT: renamable $x1 = LB %stack.0.a, 0 :: (volatile dereferenceable load (s8) from %ir.a) + ; CHECK-NEXT: SW killed renamable $x1, %stack.0.a, 0 :: (volatile store (s32) into %ir.a) ; CHECK-NEXT: renamable $x1 = LW %stack.1, 0 :: (load (s32) from %stack.1) ; CHECK-NEXT: SW killed renamable $x1, %stack.0.a, 0 :: (volatile store (s32) into %ir.a) ; CHECK-NEXT: SW $x10, %stack.0.a, 0 :: (volatile store (s32) into %ir.a)