This is an archive of the discontinued LLVM Phabricator instance.

[mlir][transforms] Simplify OperationEquivalence and CSE
ClosedPublic

Authored by springerm on Jan 25 2023, 8:45 AM.

Details

Summary

Replace mapOperands and mapResults with two new callbacks. It was not clear what "mapping" meant and why the equivalence relationship was a property of the Operand/OpResult as opposed to just SSA values.

OperationEquivalence::isEquivalentTo can be used directly in CSE and there is no need for a custom op equivalence analysis.

Diff Detail

Event Timeline

springerm created this revision.Jan 25 2023, 8:45 AM
springerm requested review of this revision.Jan 25 2023, 8:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 8:45 AM
springerm edited the summary of this revision. (Show Details)Jan 25 2023, 8:46 AM

This probably needs more tests but let me know if it makes sense overall.

springerm updated this revision to Diff 492143.Jan 25 2023, 9:03 AM

split change

springerm retitled this revision from [mlir][transforms] Simplify OperationEquivalence and CSE ops with multiple regions to [mlir][transforms] Simplify OperationEquivalence and CSE.Jan 25 2023, 9:04 AM
springerm edited the summary of this revision. (Show Details)
springerm edited the summary of this revision. (Show Details)
mehdi_amini added inline comments.Jan 25 2023, 10:01 AM
mlir/include/mlir/IR/OperationSupport.h
940

There is a change in contract here for markEquivalent. Ideally this should be done in a separate patch, if it is too involved by now, can you at least document and motivate this in the description?

mlir/lib/IR/OperationSupport.cpp
759

Seems like we should first check here if (curArg == otherArg) continue; instead of relying on every checkEquivalent callback to do so.

We should also better document these invariants in the isEquivalentTo() API doc.

This is pretty cool! It makes CSE very powerful. Last time I edited, I tried to walk a fine line and take small steps. So thanks for cleaning all of these up! This is taking a big step. I think its OK. But I'll probably wait for others to chime in.

mlir/lib/IR/OperationSupport.cpp
679

Is this something that we can assert by just looking at the arguments. The intent of mapOperands was to let the caller decide if the two basic block arguments (at same position and type are equivalent). This is now doing the reverse... It is making the assertion that two basic block arguments at same position and type of an operation are the same. I think its OK, but I am not an expert in novel ways people use MLIR/intended use of regions, etc. Just pointing out that this contract has flipped here (as Mehdi pointed out too)

springerm updated this revision to Diff 492363.Jan 26 2023, 2:08 AM
springerm marked 3 inline comments as done.

address comments

mlir/include/mlir/IR/OperationSupport.h
940

I'm not sure how to split it further. (D142562 used to be part of this and that's the only thing that I could easily put into a separate change.) Improved the documentation of isEquivalentTo and the commit message.

mlir/lib/IR/OperationSupport.cpp
679

Yes this change in contract was on purpose to simplify the API. Users can still override this by providing a custom checkEquivalent.

mehdi_amini accepted this revision.Jan 26 2023, 5:29 PM
This revision is now accepted and ready to land.Jan 26 2023, 5:29 PM
This revision was landed with ongoing or failed builds.Jan 27 2023, 2:57 AM
This revision was automatically updated to reflect the committed changes.