This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fold some refilled/spilled subreg COPYs
ClosedPublic

Authored by gberry on Dec 5 2016, 1:06 PM.

Details

Summary

Extend AArch64 foldMemoryOperandImpl() to handle folding spills of
subreg COPYs with read-undef defs like:

%vreg0:sub_32<def,read-undef> = COPY %WZR; GPR64:%vreg0

by widening the spilled physical source reg and generating:

STRXui %XZR <fi#0>

as well as folding refills of similar COPYs like:

%vreg0:sub_32<def,read-undef> = COPY %vreg1; GPR64:%vreg0, GPR32:%vreg1

by generating:

%vreg0:sub_32<def,read-undef> = LDRWui <fi#0>

Diff Detail

Repository
rL LLVM

Event Timeline

gberry updated this revision to Diff 80315.Dec 5 2016, 1:06 PM
gberry retitled this revision from to [AArch64] Fold some refilled/spilled subreg COPYs.
gberry updated this object.
gberry added reviewers: MatzeB, qcolombet.
gberry added a subscriber: llvm-commits.
gberry added a comment.Dec 5 2016, 1:10 PM

This is a more general version of D27002

MatzeB edited edge metadata.Dec 5 2016, 2:01 PM

Generally looks fine, but I have some remarks.

lib/Target/AArch64/AArch64InstrInfo.cpp
2629 ↗(On Diff #80315)

Either use the term fill or reload (I personally prefer the latter) but not refill. Should probably change that in the comment as well.

I wonder if the code would become slightly cleaner if you put the spill/refill check into a single outer if and move the other ifs inside of that accordingly (you have to split up/duplicate the DstMO.getSubReg() == 0 && SrcMO.getSubReg() == 0 check but that should be fine).

2642–2643 ↗(On Diff #80315)

Maybe you can delay the computation of the register classes until one of the if conditions is fulfilled (because getMinimalPhysRegClass() isn't that fast).

2646 ↗(On Diff #80315)

I think DestRC.getSize() == SrcRC.getSize() must be true for a copy without subreg indexes, so it can be an assert.

2664–2665 ↗(On Diff #80315)

TargetRegisterInfo::isPhysicalRegister(SrcReg) should imply SrcMO.getSubReg() == 0, so the latter can be an assert.

2666 ↗(On Diff #80315)

This condition be combined with the preceding if.

2670–2675 ↗(On Diff #80315)

The listing of GPR64commonRegClass, GPR64spRegClass, ... seems a bit arbitrary (if someone adds a new class he will probably miss updating this piece of code). Also I can see this failing if the copy is actually from SP and you change GPR64spRegClass to GPR64.

Maybe what we really want here is something like

if (GPR64RegClass.contains(SrcReg))
  SpillRC = GPR64RegClass;
else if (GPR32RegClass.contains(SrcReg))
  SpillRc = GPR32RegClass;
else
  SpillRc = &DstRC;

?

2686 ↗(On Diff #80315)

Use fill or reload.

2697–2708 ↗(On Diff #80315)

I wish we had a function that given a regclass + subregindex would return the class that results from applying the subregindex to all registers in regclass. Surprisingly I couldn't find such a function, may be worth investigating at some point what it takes to create that. (Of course this is independent of this commit, we can leave this for now I think).

2714 ↗(On Diff #80315)

Use a reference?

gberry marked 9 inline comments as done.Dec 6 2016, 9:31 AM
gberry added inline comments.
lib/Target/AArch64/AArch64InstrInfo.cpp
2629 ↗(On Diff #80315)

I don't think this refactoring makes it much easier to read, especially given the fixups that have to be done to the load in the fill, read-undef case, but let me know if you disagree.

2670–2675 ↗(On Diff #80315)

I believe I have addressed this in my update.

2697–2708 ↗(On Diff #80315)

Yeah, I also looked for just such a function, but this code is slightly more general in that it will handle cross-bank COPYs as well.

gberry updated this revision to Diff 80439.Dec 6 2016, 9:32 AM
gberry marked 3 inline comments as done.
gberry edited edge metadata.

New version addressing Matthias' comments.

MatzeB accepted this revision.Jan 2 2017, 5:36 AM
MatzeB edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 2 2017, 5:36 AM
This revision was automatically updated to reflect the committed changes.