This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Add br_unless, implement ReverseBranchCondition, and re-enable MachineBlockPlacement
ClosedPublic

Authored by sunfish on Nov 25 2015, 12:28 PM.

Details

Summary

Pending https://github.com/WebAssembly/design/pull/481 , this is a patch implementing br_unless in LLVM and some optimizations that are significantly easier to implement using it.

Diff Detail

Repository
rL LLVM

Event Timeline

sunfish updated this revision to Diff 41168.Nov 25 2015, 12:28 PM
sunfish retitled this revision from to [WebAssembly] Add br_unless, implement ReverseBranchCondition, and re-enable MachineBlockPlacement.
sunfish updated this object.
sunfish set the repository for this revision to rL LLVM.
sunfish added subscribers: jfb, dschuff.

This would also be accompanied by this change: https://github.com/WebAssembly/experimental/commit/cfd8a9dab3c188f9919bd938fcfa5446711ab6fe

The test diffs in that commit also give a pretty good illustration of the effect of this patch on codegen.

sunfish updated this revision to Diff 41938.Dec 4 2015, 2:09 PM

As an interim solution, to let this patch move forward without waiting for the spec process, this update adds a patch to lower br_unless into br_if, reversing the condition in place if possible, or negating the condition manually if necessary.

This may also motivate adding more floating-point comparison operators, or a dedicated not operator, if br_unless itself does not advance.

jfb added a comment.Dec 4 2015, 5:17 PM

Don't you want an option to disable the pass as well, so that we can let people compare the code for both easily?

lib/Target/WebAssembly/WebAssemblyInstrControl.td
36 ↗(On Diff #41938)

This is only I32 because that's what we lower bool to, correct? Could you add a comment explaining it?

lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
131 ↗(On Diff #41938)

&& "comment"

151 ↗(On Diff #41938)

Ditto.

lib/Target/WebAssembly/WebAssemblyLowerBrUnless.cpp
102 ↗(On Diff #41938)

Start with Inverted = true and set Inverted = false for default?

sunfish updated this revision to Diff 41965.Dec 4 2015, 5:31 PM

Updated for review comments.

jfb added a comment.Dec 4 2015, 5:39 PM

One file got lost in the update I think.

sunfish marked 3 inline comments as done.Dec 4 2015, 5:44 PM

I hadn't planned to add an option; I tend to prefer to avoid checking in command-line options for experiments.

lib/Target/WebAssembly/WebAssemblyInstrControl.td
37 ↗(On Diff #41965)

Correct.

sunfish updated this revision to Diff 41967.Dec 4 2015, 5:44 PM
sunfish marked an inline comment as done.

Fix missing file in previous patch.

jfb accepted this revision.Dec 4 2015, 5:53 PM
jfb added a reviewer: jfb.

I think it would make the discussion easier if folks could try both, but the patch looks fine for now.

This revision is now accepted and ready to land.Dec 4 2015, 5:53 PM
This revision was automatically updated to reflect the committed changes.