Skip to content

MIPS: Implement isAsCheapAsAMove for addiu #133273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions llvm/lib/Target/Mips/MipsInstrInfo.cpp
Original file line number Diff line number Diff line change
@@ -678,6 +678,22 @@ bool MipsInstrInfo::HasLoadDelaySlot(const MachineInstr &MI) const {
}
}

bool MipsInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
const unsigned Opcode = MI.getOpcode();
switch (Opcode) {
default:
break;
case Mips::ADDiu:
case Mips::ADDiu_MM:
case Mips::DADDiu:
return ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
(MI.getOperand(1).isReg() &&
(MI.getOperand(1).getReg() == Mips::ZERO ||
MI.getOperand(1).getReg() == Mips::ZERO_64)));
}
return MI.isAsCheapAsAMove();
}

/// Return the number of bytes of code the specified instruction may be.
unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
switch (MI.getOpcode()) {
2 changes: 2 additions & 0 deletions llvm/lib/Target/Mips/MipsInstrInfo.h
Original file line number Diff line number Diff line change
@@ -113,6 +113,8 @@ class MipsInstrInfo : public MipsGenInstrInfo {
/// Predicate to determine if an instruction has a load delay slot.
bool HasLoadDelaySlot(const MachineInstr &MI) const;

bool isAsCheapAsAMove(const MachineInstr &MI) const override;

/// Insert nop instruction when hazard condition is found
void insertNoop(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const override;