This is an archive of the discontinued LLVM Phabricator instance.

Fix MemorySSAUpdater::insertDef for dead code
ClosedPublic

Authored by apilipenko on Mar 28 2022, 11:07 AM.

Details

Summary

Currently, the attached test case fails with an assert in MemorySSAUpdater::fixupDefs:

// We are now this def's defining access, make sure we actually dominate
// it
assert(MSSA->dominates(NewDef, FirstDef) &&
       "Should have dominated the new access");

See https://github.com/llvm/llvm-project/issues/51257

This happens because we are trying to insert a def in dead code. In this test case GVN attempts to merge baz.invoke block into dead.block (both blocks are dead, i.e. unreachable from entry). This triggers an update to MemorySSA with the following call chain:

MergeBlockIntoPredecessor
  MemorySSAUpdater::moveToPlace
    MemorySSAUpdater::moveTo
      MemorySSAUpdater::insertDef
        MemorySSAUpdater::fixupDefs

fixupDefs asserts that the new defining access dominates the memory access being updated. This assert fails for dead code because DomTree doesn't provide dominance information for blocks not reachable from entry (it simply returns false).

When constructing a fresh MSSA we mark all memory accesses in dead code as live-on-entry. In this patch, I do the same for incremental updates via insertDef.

Diff Detail

Event Timeline

apilipenko created this revision.Mar 28 2022, 11:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 11:07 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
apilipenko requested review of this revision.Mar 28 2022, 11:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 11:07 AM
fhahn accepted this revision.Mar 29 2022, 1:39 AM

LGTM, thanks! Please wait a day or so with committing, in case others have additional comments. In terms of test location, it might be good to place it under Transforms/GVN as this is causing by an update through a transformation. But we are not really strict with avoiding running transforms in Analysis tests, so whatever should be fine.

This revision is now accepted and ready to land.Mar 29 2022, 1:39 AM

Looks good to me as well.

asbirlea accepted this revision.Mar 29 2022, 10:44 AM
This revision was landed with ongoing or failed builds.Mar 31 2022, 4:33 PM
This revision was automatically updated to reflect the committed changes.