[mlir][CSE] Add ability to remove commutative operations
authorValentin Clement <clementval@gmail.com>
Sat, 16 Apr 2022 19:08:16 +0000 (21:08 +0200)
committerValentin Clement <clementval@gmail.com>
Sat, 16 Apr 2022 19:09:47 +0000 (21:09 +0200)
commitbd514967aa221bef5d1adaec12abc68511f325f0
tree55156a5ada35fa9dd6d16f5a819f6a7aec13c327
parentbf59cd72447facdb7b17fc00c502d18a02135abb
[mlir][CSE] Add ability to remove commutative operations

This patch takes advantage of the Commutative trait on operation
to remove identical commutative operations where the operands are swapped.

The second operation below can be removed since `arith.addi` is commutative.
```
%1 = arith.addi %a, %b : i32
%2 = arith.addi %b, %a : i32
```

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123492
mlir/lib/IR/OperationSupport.cpp
mlir/test/Transforms/cse.mlir