This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Allow speculating block containing assume()
ClosedPublic

Authored by nikic on Nov 3 2022, 7:59 AM.

Details

Summary

SpeculativelyExecuteBB(), which converts a branch + phi structure into a select, currently bails out if the block contains an assume (because it is not speculatable).

Adjust the fold to ignore ephemeral values (i.e. assumes and values only used in assumes) for cost modelling purposes, and drop them when performing the fold.

Theoretically, we could try to preserve the assume information by generating a assume(br_cond || assume_cond) style assume, but this is very unlikely to to be useful (because we don't do anything useful with assumes of this form) and it would make things substantially more complicated once we take operand bundle assumes into account (which don't really support a || operation). I'd prefer not to do that without good motivation.

Diff Detail

Event Timeline

nikic created this revision.Nov 3 2022, 7:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 7:59 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Nov 3 2022, 7:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 7:59 AM
nikic added inline comments.Nov 3 2022, 8:01 AM
llvm/test/Transforms/SimplifyCFG/two-entry-phi-fold-crash.ll
17

A bit non-obvious why this is affected, as there are no assumes here: The load result is unused, so this is effectively an ephemeral value as well.

aeubanks accepted this revision.Nov 3 2022, 11:25 AM
This revision is now accepted and ready to land.Nov 3 2022, 11:25 AM
This revision was landed with ongoing or failed builds.Nov 4 2022, 1:27 AM
This revision was automatically updated to reflect the committed changes.