This is an archive of the discontinued LLVM Phabricator instance.

[NARY] Don't optimize min/max if there are side uses (part2)
ClosedPublic

Authored by ebrevnov on Apr 27 2021, 6:16 AM.

Details

Summary

Previous attempt to fix infinite recursion in min/max reassociation was not fully successful (D100170). Newly discovered failing case is due to not properly handled when there is a single use. It should be processed separately from 2 uses case.

Diff Detail

Event Timeline

ebrevnov created this revision.Apr 27 2021, 6:16 AM
ebrevnov requested review of this revision.Apr 27 2021, 6:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2021, 6:16 AM
ebrevnov edited the summary of this revision. (Show Details)Apr 27 2021, 6:21 AM
ebrevnov added a reviewer: mkazantsev.
ebrevnov updated this revision to Diff 341445.Apr 29 2021, 2:56 AM
ebrevnov edited the summary of this revision. (Show Details)

Renaming

mkazantsev added inline comments.Apr 30 2021, 2:33 AM
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
622

How is this even possible? I could not find explaining comment here, but intuitively LHS and RHS are expected to be arguments of I. If LHS has the only user then it must be I. no?

Could you please add a method comment about what I, LHS and RHS actually are?

ebrevnov added inline comments.Apr 30 2021, 3:16 AM
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
622

Yes, your understanding is correct. LHS & RHS simply left and right operands of I (which is min/max or select). I will updated the code shortly

ebrevnov updated this revision to Diff 341830.Apr 30 2021, 3:38 AM

Added comment + removed useless check + replaced explicit for with llvm::any_of

mkazantsev added inline comments.Apr 30 2021, 3:51 AM
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
620–623

Please limit capture scope to &I (it doesn'tseem you need anythong else).

621

Is U != I even happens to be false? An instruction can only use itself it it's a Phi, and I believe I is not a Phi here.

mkazantsev added inline comments.Apr 30 2021, 3:57 AM
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
621

Ah it's a user of LHS and not I. Makes sense then.

mkazantsev accepted this revision.Apr 30 2021, 4:33 AM

Looks good now, thanks.

This revision is now accepted and ready to land.Apr 30 2021, 4:33 AM