Optimize away zero-length MCP/MCPI instructions#7629
Conversation
FuelVM's MCP with length=0 is a no-op at runtime: no panic, no memory change. Remove zero-length MCP (when length register is $zero) and MCPI (when immediate is 0) in remove_redundant_ops(), saving bytecode size and execution cost. Closes FuelLabs#7624
Verify that an inline asm mcp with zero length register is present in the IR but optimized away in the final assembly output.
PR SummaryLow Risk Overview Adds Reviewed by Cursor Bugbot for commit 8d92e1a. Bugbot is set up for automated code reviews on this repo. Configure here. |
2323409 to
8cd8513
Compare
|
@Dnreikronos You may need to run |
Adjusted! |
|
Thanks for the contribution! Before we can merge this, we need @Dnreikronos to sign the Fuel Labs Contributor License Agreement. |
|
@Dnreikronos We currently have an issue with the CLA signing. I hope it will be solved soon. Thank you for your contribution and please bear with us until the verification step is fixed. |
|
@Dnreikronos the CLA bot should be back in working order. Appreciate your patience and your contribution! |
|
👍 |
|
@Dnreikronos Did you try to sign the CLA? |
|
|
Now worked, @ironcev :) |


Description
MCPwith length=0 does nothing at runtime in FuelVM: no panic, no memory change. It resets$errto 0, but every instruction does that anyway. So we can safely strip these out.This adds two match arms to
remove_redundant_ops():MCP(_, _, len)wherelenis$zero(set by constant propagation)MCPI(_, _, imm)where the immediate is 0Since this runs after
constant_propagate()anddce(), any register known to be zero is already$zeroby the time we get here. Leftover setup instructions (likeMOVI len_reg, 0) become dead code, and DCE cleans them up on the next round.The IR-level path (
compile_mem_copy_bytes) already skips zero-length copies at compile time. This catches the cases that only resolve to zero after constant propagation at the ASM level (inline ASM paths,Vecpush of empty slices, etc.).Closes #7624
Checklist
core/trybuild, if needed.Breaking*orNew Featurelabels, if relevant.Test plan
mcp_zero_len.swIR generation test: checks thatmcpshows up in the IR but is gone from final ASM (not: mcpfilecheck directive)forc build --asm finalon a script usingasm { mcp dst src zero; }, nomcpin output