This is an archive of the discontinued LLVM Phabricator instance.

[Transforms/ObjCARC] Fix non-deterministic output of `ObjCARCOptPass`
ClosedPublic

Authored by akyrtzi on Oct 6 2022, 10:40 AM.

Details

Summary

ProvenanceAnalysis::related() was assuming that the order of parameters for relatedCheck() was not affecting
the result but this was not the case when both parameters were PHINodes.
Due to this assumption ProvenanceAnalysis::related() was ordering the parameters based on pointer value which resulted in
non-deterministic behavior.

To address this change relatedPHI() so that it gives the same result independent of the parameter order.

rdar://100325456

Diff Detail

Event Timeline

akyrtzi created this revision.Oct 6 2022, 10:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 10:40 AM
akyrtzi requested review of this revision.Oct 6 2022, 10:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 10:40 AM
ahatanak added inline comments.Oct 12 2022, 7:46 AM
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
80–81

This function returns true if either comparePHISources(PNB, A) or comparePHISources(A, B) returns true. Should it return false if either comparePHISources(PNB, A) or comparePHISources(A, B) returns false instead? I think related returns true when the two pointers are related but also when it doesn't know the answer (i.e., it's being conservative). On the other hand, it returns false only when it's certain that the two pointers aren't related.

akyrtzi added inline comments.Oct 12 2022, 8:19 AM
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
80–81

To make sure I understand, the semantics we want here is that two PHINodes are only considered related if they both have a source value that is related to the other, and if only one PHINode has a source value related to the other, but not the other PHINode, then they should not be considered related. Is this correct?

ahatanak added inline comments.Oct 12 2022, 10:07 AM
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
80–81

Yes, that was what I was thinking.

akyrtzi updated this revision to Diff 467256.Oct 12 2022, 1:58 PM

ProvenanceAnalysis::relatedPHI: Return true only if both comparePHISources() calls return true

akyrtzi marked 2 inline comments as done.Oct 12 2022, 1:59 PM
akyrtzi added inline comments.
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
80–81

Thank you for the feedback! 🙇🏻‍♂️ See updated patch.

akyrtzi updated this revision to Diff 467258.Oct 12 2022, 2:01 PM
akyrtzi marked an inline comment as done.

Fix the patch.

ahatanak accepted this revision.Oct 14 2022, 9:28 AM

LGTM

llvm/test/Transforms/ObjCARC/related-check.ll
110

Instead of running opt twice and comparing the output using diff, you can just check (using FileCheck) that the phi in this block is eliminated and the release below (the second one) is moved.

This revision is now accepted and ready to land.Oct 14 2022, 9:28 AM
akyrtzi added inline comments.Oct 14 2022, 10:41 AM
llvm/test/Transforms/ObjCARC/related-check.ll
110

This test is less about the specific effects of the transformation and more about checking that the behavior of the transformation is deterministic.

ahatanak added inline comments.Oct 14 2022, 10:48 AM
llvm/test/Transforms/ObjCARC/related-check.ll
110

OK, I see.