Skip to content

Commit 8cf6778

Browse files
committed
[RISC-V] Implement RISCVInstrInfo::isCopyInstrImpl()
This does not result in changes for any of the current tests, but it might improve debug information in some cases. Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D86522
1 parent fa6da90 commit 8cf6778

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ bool RISCVInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
517517
break;
518518
case RISCV::FSGNJ_D:
519519
case RISCV::FSGNJ_S:
520-
// The canonical floatig-point move is fsgnj rd, rs, rs.
520+
// The canonical floating-point move is fsgnj rd, rs, rs.
521521
return MI.getOperand(1).isReg() && MI.getOperand(2).isReg() &&
522522
MI.getOperand(1).getReg() == MI.getOperand(2).getReg();
523523
case RISCV::ADDI:
@@ -530,6 +530,28 @@ bool RISCVInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
530530
return MI.isAsCheapAsAMove();
531531
}
532532

533+
Optional<DestSourcePair>
534+
RISCVInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
535+
if (MI.isMoveReg())
536+
return DestSourcePair{MI.getOperand(0), MI.getOperand(1)};
537+
switch (MI.getOpcode()) {
538+
default:
539+
break;
540+
case RISCV::ADDI:
541+
if (MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0)
542+
return DestSourcePair{MI.getOperand(0), MI.getOperand(1)};
543+
break;
544+
case RISCV::FSGNJ_D:
545+
case RISCV::FSGNJ_S:
546+
// The canonical floating-point move is fsgnj rd, rs, rs.
547+
if (MI.getOperand(1).isReg() && MI.getOperand(2).isReg() &&
548+
MI.getOperand(1).getReg() == MI.getOperand(2).getReg())
549+
return DestSourcePair{MI.getOperand(0), MI.getOperand(1)};
550+
break;
551+
}
552+
return None;
553+
}
554+
533555
bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
534556
StringRef &ErrInfo) const {
535557
const MCInstrInfo *MCII = STI.getInstrInfo();

llvm/lib/Target/RISCV/RISCVInstrInfo.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class RISCVInstrInfo : public RISCVGenInstrInfo {
8383

8484
bool isAsCheapAsAMove(const MachineInstr &MI) const override;
8585

86+
Optional<DestSourcePair>
87+
isCopyInstrImpl(const MachineInstr &MI) const override;
88+
8689
bool verifyInstruction(const MachineInstr &MI,
8790
StringRef &ErrInfo) const override;
8891

0 commit comments

Comments
 (0)