This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix a bug in removing unnecessary branches
ClosedPublic

Authored by aheejin on May 26 2020, 9:13 AM.

Details

Summary

One of the things removeUnnecessaryInstrs() in CFGStackify does is to
remove an unnecessary unconditinal branch before an EH pad. When there
is an unconditional branch right before a catch instruction and it
branches to the end of end_try marker, we don't need the branch,
because it there is no exception, the control flow transfers to
that point anyway.

bb0:
  try
    ...
    br bb2      <- Not necessary
bb1:
  catch
    ...
bb2:
  end

This applies when we have a conditional branch followed by an
unconditional one, in which case we should only remove the unconditional
branch. For example:

bb0:
  try
    ...
    br_if someplace_else
    br bb2                 <- Not necessary
bb1:
  catch
    ...
bb2:
  end

But TargetInstrInfo::removeBranch we used removed all existing
branches when there are multiple ones. This patch fixes it by only
deleting the last (= unconditional) branch manually.

Also fixes some preds comments in the test file.

Diff Detail

Event Timeline

aheejin created this revision.May 26 2020, 9:13 AM
dschuff accepted this revision.May 28 2020, 3:52 PM
This revision is now accepted and ready to land.May 28 2020, 3:52 PM

oh also "WebbAssembly" in the CL title should be "WebAssembly"

aheejin retitled this revision from [WebbAssembly] Fix a bug in removing unnecessary branches to [WebAssembly] Fix a bug in removing unnecessary branches.May 28 2020, 5:50 PM
This revision was automatically updated to reflect the committed changes.