Bug in `OperationEquivalence` (breaks `-cse` on `linalg.index`)

We had an ODM to discuss the issues pertaining to side effects and operation equivalence: MLIR Open Meeting: Side Effect Semantics, CSE and Linalg ops, 2025-05-06. No definitive solution yet, but there are signs of a possible consensus on extending OperationEquivalence to account for an interface that operations may implement to restrict equivalence even if they are structurally identical. For example, linlag.index operations may declare themselves equivalent only if they have the same immediate LinalgOp parent. The main concern is currently about the cost of using an interface, and a recommendation is to work towards reducing the cost.

I have also found a previous related discussion: [RFC] DialectInterface for CSE that, conversely, wants to relax OperationEquivalence to allow some attributes to be intentionally excluded from equivalence queries. A related PR was approved in ⚙ D155577 [mlir][OperationEquivalence] Add an extra callback to hook operation equivalence check but fell through the cracks of Github migration and was not merged even after revival in [mlir][OperationEquivalence] Add an extra callback to hook operation equivalence check by Hardcode84 · Pull Request #73455 · llvm/llvm-project · GitHub, [mlir][CSE] Introduce DialectInterface for CSE by Hardcode84 · Pull Request #73520 · llvm/llvm-project · GitHub. If we do find an interface-based solution, it would be nice to account for both situations.

We may want to hold another discussion on this topic.

cc @Hardcode84 @uenoku from the previous thread.