diff --git a/llvm/lib/Target/Lanai/LanaiRegisterInfo.h b/llvm/lib/Target/Lanai/LanaiRegisterInfo.h --- a/llvm/lib/Target/Lanai/LanaiRegisterInfo.h +++ b/llvm/lib/Target/Lanai/LanaiRegisterInfo.h @@ -34,6 +34,8 @@ bool requiresRegisterScavenging(const MachineFunction &MF) const override; + bool supportsBackwardScavenger() const override { return true; } + bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS = nullptr) const override; diff --git a/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp b/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp --- a/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp +++ b/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp @@ -167,7 +167,7 @@ assert(RS && "Register scavenging must be on"); Register Reg = RS->FindUnusedReg(&Lanai::GPRRegClass); if (!Reg) - Reg = RS->scavengeRegister(&Lanai::GPRRegClass, II, SPAdj); + Reg = RS->scavengeRegisterBackwards(Lanai::GPRRegClass, II, false, SPAdj); assert(Reg && "Register scavenger failed"); bool HasNegOffset = false; @@ -235,10 +235,11 @@ .addReg(FrameReg) .addImm(-Offset); MI.eraseFromParent(); - } else { - MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, /*isDef=*/false); - MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset); + return true; } + + MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, /*isDef=*/false); + MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset); return false; }