This is an archive of the discontinued LLVM Phabricator instance.

[MemorySSA] Relax assert condition in createDefinedAccess
ClosedPublic

Authored by StephenFan on Nov 7 2022, 7:23 AM.

Details

Summary

If globals-aa is enabled, because of the deletion of memory instructions, there
may be call instruction that is not in ModOrRefSet but is a MemoryUseOrDef.
This causes the crash in the process of cloning uses and defs.

Fixes https://github.com/llvm/llvm-project/issues/58719

Diff Detail

Event Timeline

StephenFan created this revision.Nov 7 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2022, 7:23 AM
StephenFan requested review of this revision.Nov 7 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2022, 7:23 AM
fhahn added a subscriber: fhahn.Nov 7 2022, 1:05 PM
fhahn added inline comments.
llvm/test/Transforms/SimpleLoopUnswitch/pr58719.ll
2

is instcombine needed here?

5

Can this load from an actual address?

fhahn added a comment.Nov 7 2022, 1:06 PM

Thanks for the patch. it would also be great if you could mention the patch at the bug report, so people know there's a fix in the works.

StephenFan updated this revision to Diff 473856.Nov 7 2022, 6:51 PM
  1. Replace NULL as a actual address.
  2. Add function(loop-mssa(loop-simplifycfg)) in passes. Only if MemorySSA is constructed before recomputing globalsaa, the crash happens.
StephenFan added inline comments.Nov 7 2022, 6:53 PM
llvm/test/Transforms/SimpleLoopUnswitch/pr58719.ll
2

Yes. InstCombine will delete the load instruction in function f.

nikic added a comment.Nov 8 2022, 6:55 AM

I'm a bit unsure about the approach used here. Might it make more sense to relax the assertion instead? AA returning better (or worse!) results as a result of other transforms is pretty normal, so it seems fragile if code has to go out of the way to drop no longer needed MemoryAccesses to avoid assertion failures.

I'm a bit unsure about the approach used here. Might it make more sense to relax the assertion instead? AA returning better (or worse!) results as a result of other transforms is pretty normal, so it seems fragile if code has to go out of the way to drop no longer needed MemoryAccesses to avoid assertion failures.

To be honest, I have the same concerns. I will try to relax the assertion instead.

Relax assertion.

nikic added a comment.Nov 9 2022, 2:19 AM

I'm fine with this change, but would be good for @asbirlea to chime in.

asbirlea accepted this revision.Nov 15 2022, 4:29 PM
asbirlea added inline comments.
llvm/lib/Analysis/MemorySSA.cpp
1770

Could you add:

if (!Def && Use != UseCheck) {
        // New access should not have more power than template access
        assert(!UseCheck && "Invalid template");
}
This revision is now accepted and ready to land.Nov 15 2022, 4:29 PM
StephenFan retitled this revision from [MemorySSA] Delete dead MemoryUseOrDef for CallInst when clone loop basicblock to [MemorySSA] Relax assert condition in createDefinedAccess.
StephenFan edited the summary of this revision. (Show Details)

Address comments.

This revision was landed with ongoing or failed builds.Nov 17 2022, 7:43 AM
This revision was automatically updated to reflect the committed changes.