This is an archive of the discontinued LLVM Phabricator instance.

[DIArgList] Re-unique after changing operands to fix non-determinism
ClosedPublic

Authored by tejohnson on Aug 30 2021, 8:42 PM.

Details

Summary

We have a large compile showing occasional non-deterministic behavior
that is due to DIArgList not being properly uniqued in some cases. I
tracked this down to handleChangedOperands, for which there is a custom
implementation for DIArgList, that does not take care of re-uniquing
after updating the DIArgList Args, unlike the default version of
handleChangedOperands for MDNode.

Since the Args in the DIArgList form the key for the store, this seems
to be occasionally breaking the lookup in that DenseSet. Specifically,
when invoking DIArgList::get() from replaceVariableLocationOp, very
occasionally it returns a new DIArgList object, when one already exists
having the same exact Args pointers. This in turn causes a subsequent
call to Instruction::isIdenticalToWhenDefined on those two otherwise
identical DIArgList objects during a later pass to return false, leading
to different IR in those rare cases.

I modified DIArgList::handleChangedOperands to perform similar
re-uniquing as the MDNode version used by other metadata node types.
This also necessitated a change to the context destructor, since in some
cases we end up with DIArgList as distinct nodes: DIArgList is the only
metadata node type to have a custom dropAllReferences, so we need to
invoke that version on DIArgList in the DistinctMDNodes store to clean
it up properly.

Diff Detail

Unit TestsFailed

Event Timeline

tejohnson created this revision.Aug 30 2021, 8:42 PM
tejohnson requested review of this revision.Aug 30 2021, 8:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2021, 8:42 PM

[just a general: Thanks a bunch for looking into this, I understand tracking down nondeterminism is decidedly not easy]

[Thanks! Worth cherry picking this into release/13.x so that distcc/icecc/etc users can benefit ]

llvm/lib/IR/DebugInfoMetadata.cpp
1660

only used once, so perhaps just if (uniquify() != this)

Good catch - thanks for finding and fixing this, LGTM after sorting out the inline comment.

alexfh added a subscriber: alexfh.Aug 31 2021, 2:25 PM
alexfh added inline comments.
llvm/lib/IR/DebugInfoMetadata.cpp
1646

nit: Maybe wrap the body in braces, since it's multiline due to the comment?

tejohnson marked 2 inline comments as done.Sep 1 2021, 5:37 AM
tejohnson updated this revision to Diff 369906.Sep 1 2021, 5:37 AM

Address comments

This revision was not accepted when it landed; it landed in state Needs Review.Sep 1 2021, 7:04 AM
This revision was automatically updated to reflect the committed changes.