From f8f79418d6bdb14a182530ea6b83f8b9b11a553c Mon Sep 17 00:00:00 2001 From: Ammar Ratnani Date: Thu, 11 May 2023 22:12:21 -0400 Subject: [PATCH] Fix size calculations Previously, they weren't calculating branches and LEAs correctly --- llvm/lib/Target/LC32/LC32FrameLowering.cpp | 9 ++++++--- llvm/lib/Target/LC32/LC32InstrInfo.cpp | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/LC32/LC32FrameLowering.cpp b/llvm/lib/Target/LC32/LC32FrameLowering.cpp index aa6033ede..fd242a0ae 100644 --- a/llvm/lib/Target/LC32/LC32FrameLowering.cpp +++ b/llvm/lib/Target/LC32/LC32FrameLowering.cpp @@ -133,10 +133,12 @@ static unsigned EstimateFunctionSize(const MachineFunction &MF, // later, so over-estimate their size for the purposes of register // scavenging. if (MI.getOpcode() == LC32::BR) + ret += 16; + else if (MI.getOpcode() == LC32::C_BR_CMP_ZERO) ret += 18; - // Otherwise, handle normally - ret += TII.getInstSizeInBytes(MI); + else + ret += TII.getInstSizeInBytes(MI); } } return ret; @@ -154,7 +156,8 @@ void LC32FrameLowering::processFunctionBeforeFrameFinalized( // Count the number of scavenging slots we need: // 1. if the stack frame is too large. This is an underestimate, so compensate - // 2. if branches can be out of range + // 2. if branches can be out of range. This is an overestimate, but we still + // make contingency space. unsigned num_scav = 0; if (!isInt<6 - 1>(MFI.estimateStackSize(MF))) num_scav++; diff --git a/llvm/lib/Target/LC32/LC32InstrInfo.cpp b/llvm/lib/Target/LC32/LC32InstrInfo.cpp index 4aa1d6aca..c40375417 100644 --- a/llvm/lib/Target/LC32/LC32InstrInfo.cpp +++ b/llvm/lib/Target/LC32/LC32InstrInfo.cpp @@ -52,6 +52,9 @@ unsigned LC32InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const { // compiler, while JSR is handled in the assembler. if (d_op == LC32::JSR) return this->get(LC32::P_FARJSR).getSize(); + // Same for LEA + if (d_op == LC32::LEA) + return this->get(LC32::P_LOADCONSTW).getSize(); return d.getSize(); }