3.6.1.11 Relax Option
The -mrelax
option enables several optimizations that
relate to the efficient use of call and jump instructions.
These optimizations include replacement of the long-form call and jump instructions with
shorter and/or faster relative calls and jumps when the relative forms of the
instructions can be determined to be in range of their destination. For example, code
such as:
call foo
...
foo:
...
can be replaced with: rcall foo
...
foo:
...
when foo
is within range of the relative call. (For
more information, see 4.3.6.3 Function Pointers).When relative calls would be out of range, the compiler will attempt to replace them with
rcall
instructions to a jmp
instruction that will
'trampoline' execution to the required address. For example, code such
as: call foo
...
call foo
...
call foo
can be changed
to: rcall tramp_foo
...
rcall tramp_foo
...
rcall tramp_foo
...
tramp_foo:
jmp foo
provided the trampoline is within range of the relative calls. The
compiler will re-use an existing jmp
instruction to the required
destination if possible, to further reduce code size. Such transformations will slow
execution speed but can improve code size if there multiple calls that can be
replaced.Additionally, redundant return instructions are removed from functions with a tail call.
For example, code such as:
...
call last
return
last:
...
return
can be replaced with: ...
jmp last
last:
...
return
The -mno-relax
form of this option does not apply these optimizations
and is the default action if no option is specified.