Skip redundant jump-to-epilogue
845f7ebb17e7e764b95044fbf3e7f876dc40ebc2e9a14b8589172b31380ca2f1
When RET is in the last block.
1 parent
60a9450d
lib/std/arch/rv64/isel.rad
+7 -1
| 563 | 563 | case il::Instr::Ret { val } => { |
|
| 564 | 564 | if let v = val { |
|
| 565 | 565 | let rs = resolveVal(s, super::SCRATCH1, v); |
|
| 566 | 566 | emitMv(s, super::A0, rs); |
|
| 567 | 567 | } |
|
| 568 | - | emit::emitReturn(s.e, frame); |
|
| 568 | + | // Skip the jump to epilogue if this RET is in the last block, |
|
| 569 | + | // since the epilogue immediately follows. |
|
| 570 | + | if frame.totalSize != 0 and blockIdx + 1 == frame.epilogueBlock { |
|
| 571 | + | // Epilogue is the next block; fallthrough is sufficient. |
|
| 572 | + | } else { |
|
| 573 | + | emit::emitReturn(s.e, frame); |
|
| 574 | + | } |
|
| 569 | 575 | }, |
|
| 570 | 576 | case il::Instr::Jmp { target, args } => { |
|
| 571 | 577 | // Move arguments to target block's parameter registers. |
|
| 572 | 578 | emitBlockArgs(s, func, target, args); |
|
| 573 | 579 | // Skip branch if target is the next block (fallthrough). |