Label alignments in shorten_branches

Joern Rennecke amylaar@spamcop.net
Mon Mar 30 23:59:00 GMT 2009


Quoting Bernd Schmidt <bernds_cb1@t-online.de>:

> Revision 18357, in 1998, introduced a mechanism to keep track of label
> alignments during shorten branches.  It tries to determine the known
> alignment at every point in the function, and compute the amount of
> padding needed at every label.
>
> The problem is, to do this, we need to know the exact length of every
> instruction.  The Blackfin has a few patterns where the length
> attribute gives a maximum rather than an exact value, but even if the
> machine description is 100% accurate, there is in general no way of
> knowing the exact length of an asm statement.

There is no need to know the exact length, only conservative estimates are
needed.

> I have a testcase where the compiler produces an assembly file that has
> an out-of-range jump, because it thought the label at the start of a
> jump table (which has an alignment of 4) needs no padding, when in fact
> it needs 2 bytes of padding.
>
> Can anyone think of a way to make this code work, or should I just post
> a patch to mostly revert 18357?

This code should already work if it is used properly.
the align_fuzz function is provided to give a conservative estimate of
possible changes in the distance of two code locations due to
some instructions actually being shorter than their estimates, which
can cause alignment padding increases.



More information about the Gcc-patches mailing list