This is an archive of the discontinued LLVM Phabricator instance.

[Dominators] Don't treat multi-edge as dominating
Needs ReviewPublic

Authored by nikic on Mar 2 2022, 6:33 AM.

Details

Summary

In https://github.com/llvm/llvm-project/blob/d2edca6276d1715a02d1144eae577b3d79673d67/llvm/include/llvm/IR/Dominators.h#L201-L202 we say:

If BBE is not a unique edge between start and end of the edge, it can
never dominate the use.

And the code starting at https://github.com/llvm/llvm-project/blob/d2edca6276d1715a02d1144eae577b3d79673d67/llvm/lib/IR/Dominators.cpp#L222 does handle it this way.

However, we also have two special cases for edge-phi domination and edge-edge domination, where we consider a multi-edge to be dominating. This patch makes them non-dominating, as we don't know which edge of the multi-edge we're querying.

I'm somewhat unsure about this change, because the resulting semantics could be considered somewhat odd (an edge does not dominate itself if it is a multi-edge), but I think they match the documentation and are at least self-consistent.

Diff Detail

Event Timeline

nikic created this revision.Mar 2 2022, 6:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:33 AM
nikic requested review of this revision.Mar 2 2022, 6:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:33 AM
mkazantsev resigned from this revision.Mar 4 2022, 12:12 AM
kuhar added a comment.Mar 16 2022, 7:42 AM

I'm not too sure about the semantics either. I think it might be easier to think about if we tie this back to regular graphs without multi-edges.

My guess is that the original intention was to treat multi-edges as the same logical graph edge. With this abstraction, the existing behavior seems correct to me.

What you are proposing sounds to me similar to adding a virtual node in the middle of each duplicate edge. Is this a reasonable interpretation? If yes, this patch would appear fine to me, but I'm not sure if it's logically consistent with all the other code that may still rely on the old abstraction.