@@ -187,23 +187,21 @@ bool SBFMIPreEmitPeephole::addReturn() {
187
187
//
188
188
// Although we can change ISelLowering and manually add the return for an
189
189
// LLVM-IR unreachable instruction, LLVM codegen uses the target machine's
190
- // return instruction to determine whether a function needs an epilogue,
191
- // increasing code size more , even when we know the call won't transfer
192
- // control back to the caller.
190
+ // return instruction to determine whether a function needs an epilogue.
191
+ // This setting increases code size, even when we know the call won't
192
+ // trasnfer control back to the caller.
193
193
//
194
194
// In that case, we can analyze every function before emitting machine code
195
195
// and include a useless return instruction.
196
196
197
- for (MachineBasicBlock &MBB: *MF) {
198
- if (!MBB.succ_empty () || MBB.empty ())
199
- continue ;
200
-
201
- MachineInstr &MI = MBB.back ();
202
- unsigned Opcode = MI.getOpcode ();
203
- if (Opcode != SBF::RETURN_v3) {
204
- BuildMI (&MBB, MI.getDebugLoc (), TII->get (SBF::RETURN_v3));
205
- Added = true ;
206
- }
197
+ // PreEmitPeephole happens after block placement, so the last block in
198
+ // the ELF layout is also the last one in MF.
199
+ MachineBasicBlock &MBB = MF->back ();
200
+ MachineInstr &MI = MBB.back ();
201
+ unsigned Opcode = MI.getOpcode ();
202
+ if (Opcode != SBF::RETURN_v3 && Opcode != SBF::JMP) {
203
+ BuildMI (&MBB, MI.getDebugLoc (), TII->get (SBF::RETURN_v3));
204
+ Added = true ;
207
205
}
208
206
209
207
return Added;
0 commit comments