This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Reorganise and simplify thumb-1 load/store selection
ClosedPublic

Authored by john.brawn on Aug 6 2015, 5:16 AM.

Details

Summary

Other than PC-relative loads/store the patterns that match the various load/store addressing modes have the same complexity, so the order that they are matched is the order that they appear in the .td file.

Rearrange the instruction definitions in ARMInstrThumb.td, and make use of AddedComplexity for PC-relative loads, so that the instruction matching order is the order that results in the simplest selection logic. This also makes register-offset load/store be selected when it should, as previously it was only selected for too-large immediate offsets.

Diff Detail

Repository
rL LLVM

Event Timeline

john.brawn updated this revision to Diff 31443.Aug 6 2015, 5:16 AM
john.brawn retitled this revision from to [ARM] Reorganise and simplify thumb-1 load/store selection.
john.brawn updated this object.
john.brawn added reviewers: t.p.northover, jmolloy.
john.brawn set the repository for this revision to rL LLVM.
john.brawn added a subscriber: llvm-commits.
jmolloy requested changes to this revision.Aug 7 2015, 12:58 AM
jmolloy edited edge metadata.

Hi John,

There appears to be quite a bit of reordering going on in this diff, and I had difficulty working out if it was cleanup or if it had semantic meaning. Like moving defm _rr after defm _ri. Can you please undo this or mark what is just cleanup (and submit that separately when committing)?

I'm having difficulty understanding why you're removing the selection of register+scaled-immediate addressing modes entirely. Was that code always pessimistic? Is RO always better? A bit of explanation of the rationale would really help (and that rationale should be repeated in the commit message!)

Cheers,

James

This revision now requires changes to proceed.Aug 7 2015, 12:58 AM

There appears to be quite a bit of reordering going on in this diff, and I had difficulty working out if it was cleanup or if it had semantic meaning. Like moving defm _rr after defm _ri. Can you please undo this or mark what is just cleanup (and submit that separately when committing)?

All of the reordering is deliberate as I say (probably not clearly enough) in the summary. All of the patterns (except for the one for pc-relative load) have the same complexity so are matched in the order they appear in the .td file. Rearranging them to be pc-relative -> sp-relative -> immediate offset -> register offset means we have the least logic of the form "don't select this instruction because next I'm going to try selecting a different instruction that would be better" - in fact we only need that to avoid generating x+y as [x+y, #0] and instead do [x, y].

I'll add some comments to try and explain all this.

I'm having difficulty understanding why you're removing the selection of register+scaled-immediate addressing modes entirely. Was that code always pessimistic? Is RO always better? A bit of explanation of the rationale would really help (and that rationale should be repeated in the commit message!)

I didn't, they're still there. ARMDAGToDAGISel::SelectThumbAddrModeRI was used to select the register+register addressing mode but was written in a way that meant that it was only selected when the offset was an immediate too-large for an immediate offset.

john.brawn updated this revision to Diff 31505.Aug 7 2015, 5:15 AM
john.brawn updated this object.
john.brawn edited edge metadata.

Add some comments to hopefully clarify things.

rengolin added inline comments.Aug 7 2015, 6:21 AM
lib/Target/ARM/ARMInstrThumb.td
1385 ↗(On Diff #31505)

but this is still "favouring" register offset?

1402 ↗(On Diff #31505)

If I got it right, all of these are just saying: immediate is better than register offset?

john.brawn added inline comments.Aug 7 2015, 10:15 AM
lib/Target/ARM/ARMInstrThumb.td
1385 ↗(On Diff #31505)

Yes, looks like I missed that one. I'll fix that.

1402 ↗(On Diff #31505)

Yes. Or rather, try matching an immediate offset before trying matching a register offset.

john.brawn updated this revision to Diff 31528.Aug 7 2015, 10:18 AM
john.brawn edited edge metadata.

Swap around zextloadi1 patterns.

Looks ok to me, though I'll wait for James' final approval.

jmolloy accepted this revision.Aug 13 2015, 3:38 AM
jmolloy edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Aug 13 2015, 3:38 AM
This revision was automatically updated to reflect the committed changes.