This is an archive of the discontinued LLVM Phabricator instance.

LowerSwitch: Avoid inserting NewDefault block
ClosedPublic

Authored by ruiling on Apr 12 2022, 6:44 AM.

Details

Summary

The NewDefault was used to simplify the updating of PHI nodes, but it
causes some inefficiency for target that will run structurizer later. For
example, for a simple two-case switch, the extra NewDefault is causing
unstructured CFG like:

    O
   / \
  O   O
 / \ / \
C1  ND C2
 \  |  /
  \ | /
    D

The change is to avoid the ND(NewDefault) block, that is we will get a
structured CFG for above example like:

     O
    / \
   /   \
  O     O
 / \   / \
C1  \ /  C2
 \-> D <-/

The IR change introduced by this patch should be trivial to other targets,
so I am doing this unconditionally.

Fall-through among the cases will also cause unstructured CFG, but it need
more work and will be addressed in a separate change.

Diff Detail

Event Timeline

ruiling created this revision.Apr 12 2022, 6:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2022, 6:44 AM
ruiling requested review of this revision.Apr 12 2022, 6:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2022, 6:44 AM
arsenm accepted this revision.Apr 12 2022, 7:13 AM

LGTM. I think it's a reasonable assumption that if you're running LowerSwitch you would prefer a more structured CFG

This revision is now accepted and ready to land.Apr 12 2022, 7:13 AM

the extra NewDefault is causing unstructured CFG

Just curious: what does "unstructured CFG" mean here? Is there an exact definition? Thanks.

the extra NewDefault is causing unstructured CFG

Just curious: what does "unstructured CFG" mean here? Is there an exact definition? Thanks.

The "unstructured CFG" was used to say that a CFG could not be translated to structured programming constructs like if/else/while/... I am not sure what an exact definition should be, so feel free to correct me.

This revision was landed with ongoing or failed builds.Apr 13 2022, 10:31 PM
This revision was automatically updated to reflect the committed changes.