Index: llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp +++ llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp @@ -64,9 +64,21 @@ bool RISCVExpandAtomicPseudo::runOnMachineFunction(MachineFunction &MF) { TII = static_cast(MF.getSubtarget().getInstrInfo()); + + unsigned OldSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + OldSize += TII->getInstSizeInBytes(MI); + bool Modified = false; for (auto &MBB : MF) Modified |= expandMBB(MBB); + + unsigned NewSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + NewSize += TII->getInstSizeInBytes(MI); + assert(OldSize >= NewSize); return Modified; } Index: llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp +++ llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp @@ -56,9 +56,21 @@ bool RISCVExpandPseudo::runOnMachineFunction(MachineFunction &MF) { TII = static_cast(MF.getSubtarget().getInstrInfo()); + + unsigned OldSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + OldSize += TII->getInstSizeInBytes(MI); + bool Modified = false; for (auto &MBB : MF) Modified |= expandMBB(MBB); + + unsigned NewSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + NewSize += TII->getInstSizeInBytes(MI); + assert(OldSize >= NewSize); return Modified; } @@ -277,9 +289,21 @@ bool RISCVPreRAExpandPseudo::runOnMachineFunction(MachineFunction &MF) { TII = static_cast(MF.getSubtarget().getInstrInfo()); + + unsigned OldSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + OldSize += TII->getInstSizeInBytes(MI); + bool Modified = false; for (auto &MBB : MF) Modified |= expandMBB(MBB); + + unsigned NewSize = 0; + for (auto &MBB : MF) + for (auto &MI : MBB) + NewSize += TII->getInstSizeInBytes(MI); + assert(OldSize >= NewSize); return Modified; }