This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Stackify code emitted by eliminateFrameIndex and SP writeback
ClosedPublic

Authored by dschuff on Mar 16 2016, 5:28 PM.

Details

Summary

MRI::eliminateFrameIndex can emit several instructions to do address
calculations; these can usually be stackified. Because instructions with
FI operands can have subsequent operands which may be expression trees,
find the top of the leftmost tree and insert the code before it, to keep
the LIFO property.

Also use stackified registers when writing back the SP value to memory
in the epilog; it's unnecessary because SP will not be used after the
epilog, and it results in better code.

Diff Detail

Repository
rL LLVM

Event Timeline

dschuff updated this revision to Diff 50898.Mar 16 2016, 5:28 PM
dschuff retitled this revision from to [WebAssembly] Stackify code emitted by eliminateFrameIndex and SP writeback.
dschuff updated this object.
dschuff added reviewers: sunfish, jfb.
dschuff added a subscriber: llvm-commits.

I still need to add some lit tests for the new FI placement behavior, but I've ensured no torture regressions, and you can take a look at the approach.

To find the insertion point we could have used def/use information but a lot of it is unavailable when this pass runs, and this ended up much simpler.

Also the extra epilog stackification turns out to be important because s2wasm can reorder things (I'll post more on that tomorrow but see https://pastebin.mozilla.org/8863952 for example).

sunfish accepted this revision.Mar 17 2016, 8:56 AM
sunfish edited edge metadata.

I'll review this more closely when I get more time, but at a first readthrough it looks good.

lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
64 ↗(On Diff #50898)

Would it make sense to name this canStackifyOperand?

This revision is now accepted and ready to land.Mar 17 2016, 8:56 AM
dschuff updated this revision to Diff 50948.Mar 17 2016, 9:50 AM
dschuff edited edge metadata.
  • rename canStackify
dschuff marked an inline comment as done.Mar 17 2016, 9:51 AM
This revision was automatically updated to reflect the committed changes.