Skip to content

Commit 7eccafc

Browse files
authored
MIPS: Implement isAsCheapAsAMove for addiu (#133273)
Set `addiu` as `isAsCheapAsAMove` only when the src register or imm is zero only. If other cases are set `isAsCheapAsAMove`, MachineLICM will reject to hoist it.
1 parent 0ed8b27 commit 7eccafc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

llvm/lib/Target/Mips/MipsInstrInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,22 @@ bool MipsInstrInfo::HasLoadDelaySlot(const MachineInstr &MI) const {
678678
}
679679
}
680680

681+
bool MipsInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
682+
const unsigned Opcode = MI.getOpcode();
683+
switch (Opcode) {
684+
default:
685+
break;
686+
case Mips::ADDiu:
687+
case Mips::ADDiu_MM:
688+
case Mips::DADDiu:
689+
return ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
690+
(MI.getOperand(1).isReg() &&
691+
(MI.getOperand(1).getReg() == Mips::ZERO ||
692+
MI.getOperand(1).getReg() == Mips::ZERO_64)));
693+
}
694+
return MI.isAsCheapAsAMove();
695+
}
696+
681697
/// Return the number of bytes of code the specified instruction may be.
682698
unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
683699
switch (MI.getOpcode()) {

llvm/lib/Target/Mips/MipsInstrInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class MipsInstrInfo : public MipsGenInstrInfo {
113113
/// Predicate to determine if an instruction has a load delay slot.
114114
bool HasLoadDelaySlot(const MachineInstr &MI) const;
115115

116+
bool isAsCheapAsAMove(const MachineInstr &MI) const override;
117+
116118
/// Insert nop instruction when hazard condition is found
117119
void insertNoop(MachineBasicBlock &MBB,
118120
MachineBasicBlock::iterator MI) const override;

0 commit comments

Comments
 (0)