Skip redundant jump-to-epilogue

f1866dc6a547e1eb7bbb7c1df44a7f3bd1f7a5ce2477188793902f9fed8420d2
When RET is in the last block.
Alexis Sellier committed ago 1 parent 6d205c4f
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).