[PATCH] [MC] bundle alignment: prevent padding instructions from crossing bundle boundaries

Derek Schuff dschuff at google.com
Wed Jan 30 15:08:18 PST 2013


Typos fixed, and unnecessary comment removed.

On Wed, Jan 30, 2013 at 2:47 PM, Eli Bendersky <eliben at google.com> wrote:
> +    unsigned TotalLength = static_cast<unsigned>(FragmentSize) + BundlePadding;
> +    if (F.alignToBundleEnd() && TotalLength > Asm.getBundleAlignSize()) {
> +      // If the padding itself crosses a bundle boundary, it must be emitted
> +      // in 2 pieces, since even nop instructions must not cross boundaries.
> +      unsigned DistanceToBoundary = TotalLength - Asm.getBundleAlignSize();
>
> Are you sure it shouldn't be: Asm.getBundleAlignSize() - FragmentSize ?

BundleAlignSize - FragmentSize is the distance from the beginning of
the next bundle to the beginning of the current fragment. We want the
distance from the end of the last fragment to the beginning of the
next bundle.

In other words: (end of last fragment) + TotalLength = (end of current
fragment),
(end of last fragment) + DistanceToBoundary + (distance from boundary
to beginning of current fragment) + FragmentSize = (end of current
fragment) = (end of next bundle)
and
TotalLength = FragmentSize + BundlePadding = BundleAlignSize +
DistanceToBoundary

I don't know if that way of putting it is any clearer, but I think it's correct.



More information about the llvm-commits mailing list