Latest Results
Optimize away zero-length MCP/MCPI instructions (#7629)
## Description
`MCP` with length=0 does nothing at runtime in FuelVM: no panic, no
memory change. It resets `$err` to 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)` where `len` is `$zero` (set by constant propagation)
- `MCPI(_, _, imm)` where the immediate is 0
Since this runs after `constant_propagate()` and `dce()`, any register
known to be zero is already `$zero` by the time we get here. Leftover
setup instructions (like `MOVI 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, `Vec`
push of empty slices, etc.).
Closes #7624
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (Forc, Sway book,
etc.).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a) parsing test in `core/trybuild`, if
needed.
- [x] I have added the necessary `Breaking*` or `New Feature` labels, if
relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/0014-code-standards.md).
- [x] I have requested a review from the relevant team or maintainers.
## Test plan
- `mcp_zero_len.sw` IR generation test: checks that `mcp` shows up in
the IR but is gone from final ASM (`not: mcp` filecheck directive)
- All 78 IR generation tests still pass
- Manually confirmed with `forc build --asm final` on a script using
`asm { mcp dst src zero; }`, no `mcp` in output
---------
Co-authored-by: Igor Rončević <ironcev@hotmail.com> Latest Branches
+10%
xunilrj/fix-redundant-ops 0%
Dnreikronos:fix/index-read-ref-mut-array-7602 0%
Dnreikronos:Dnreikronos/optimize-mcp-zero-length © 2026 CodSpeed Technology