When the target of a branch is too far away from the branch itself, i.e., when the offset from the branch to the target is too large to fit in the immediate field of the branch instruction, it may be necessary to replace the branch with a branch around a jump. For example,
beqz a2, L
may result in:
bnez.n a2, M j L M:
(The BNEZ.N
instruction would be used in this example only if the
density option is available. Otherwise, BNEZ
would be used.)
This relaxation works well because the unconditional jump instruction has a much larger offset range than the various conditional branches. However, an error will occur if a branch target is beyond the range of a jump instruction. as cannot relax unconditional jumps. Similarly, an error will occur if the original input contains an unconditional jump to a target that is out of range.
Branch relaxation is enabled by default. It can be disabled by using
underscore prefixes (see Opcode Names), the
--no-transform command-line option (see Command Line Options), or the no-transform
directive
(see transform).