This is an archive of the discontinued LLVM Phabricator instance.

[LoopDeletion] Benefit from branches by undef conditions when symbolically executing 1st iteration
ClosedPublic

Authored by mkazantsev on Jun 21 2021, 11:00 PM.

Details

Summary

We can exploit branches by undef condition. Frankly, the LangRef says that
such branches are UB, so we can assume that all outgoing edges of such blocks
are dead.

However, from practical perspective, we know that this is not supported correctly
in some other places. So we are being conservative about it.

Branch by undef is treated in the following way:

  • If it is a loop-exiting branch, we always assume it exits the loop;
  • If not, we arbitrarily assume it takes true value.

Diff Detail

Event Timeline

mkazantsev created this revision.Jun 21 2021, 11:00 PM
mkazantsev requested review of this revision.Jun 21 2021, 11:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2021, 11:00 PM

Rebased on top of updated tests (w/o br i1 undef).

aqjune added inline comments.Jun 23 2021, 9:46 AM
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
355

If BB -> IfFalse edge is already live, would it be beneficial if IfFalse is chosen instead?

nikic accepted this revision.Jun 27 2021, 1:47 PM

LGTM. I don't like it, but it's in line with current approaches used elsewhere.

llvm/lib/Transforms/Scalar/LoopDeletion.cpp
355

Blocks are only visited once, so neither edge can be marked live at this point.

This revision is now accepted and ready to land.Jun 27 2021, 1:47 PM
This revision was landed with ongoing or failed builds.Jun 27 2021, 9:41 PM
This revision was automatically updated to reflect the committed changes.