[llvm-commits] [patch] Improve register coalescing

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Jun 29 15:34:18 PDT 2011


On Jun 29, 2011, at 2:46 PM, Rafael Ávila de Espíndola wrote:

> This patch improves register coalescing so that it doesn't give up on coalescing A and B if a BB contains:
> 
> A = X
> B = X
> 
> Instead, we pretend that it was
> 
> A = X
> B = A
> 
> This helps a lot in some degenerate cases, but help even in more common ones. A self hosted clang goes from 33627704 to 33626776 bytes, but jsinterp.o in firefox goes from 2069728 to 1598504 bytes.
> 
> This also speeds up the hard case. llc on jsinterp.bc goes from 23.17s to 13.34s.

Nice!

> +static bool RegistersDefinedFromSameValue(const TargetRegisterInfo &tri,
> +                                          CoalescerPair &CP, MachineInstr *MI,
> +                                          LiveRange *lr,
> +                                      SmallVector<MachineInstr*, 8> &DupCopies) {
> +

This function is a little weird, it is not really clear what the arguments mean, or what the function does. Please add more comments.

> +  unsigned Src, Dst, SrcSub, DstSub;
> +  if (!isMoveInstr(tri, MI, Src, Dst, SrcSub, DstSub))
> +    return false;
> +
> +  if (!MI->isCopy() || SrcSub || DstSub ||
> +      !TargetRegisterInfo::isVirtualRegister(Src) ||
> +      !TargetRegisterInfo::isVirtualRegister(Dst))
> +    return false;

This is pretty convoluted. First you check for a general copy-like instruction, and then you restrict to only copies afterwards.

I think is it better to add a MI->isFullCopy that returns true for copies without sub-register operands. See also isFullCopyOf() in InlineSpiller.cpp.

> +  if (!TargetRegisterInfo::isVirtualRegister(A) ||
> +      !TargetRegisterInfo::isVirtualRegister(B))
> +    return false;

A.k.a CP.isPhys()

I am not completely sure you are handling sub-registers correctly. You should probably disable this when CP.isPartial().

Would it be possible to do more complete value-based checking? For example, you don't handle this:

X = Y
A = X
B = Y

Thanks for working on this!

/jakob



More information about the llvm-commits mailing list