<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60050>60050</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
CSE Pass has no effect on ops with the same region
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Gxiandy
</td>
</tr>
</table>
<pre>
Hi all,
When using CSE pass, I found that if an Op has Region attribute, CSE Pass will just look into its region, and do CSE on the ops in its region. But actually, if two ops has the same region( which means all ops in their region are same and has no side effect), these two ops should also be treated as common sub-expression and should keep only one of them.
For example, if we have the following IR
`func.func @cse(%arg0: memref<12x64x64x64xsi8>) -> memref<12x57x57x64xsi8> {
%0 = "const"() {values = <3> : tensor<64x2xsi64>} : () -> memref<64x2xsi64>
%1 = "const"() {values = <2> : tensor<64x8x8x1xsi8>} : () -> memref<64x8x8x1xsi8>
%2 = "conv"(%arg0, %1, %0) ({}) {} : (memref<12x64x64x64xsi8>, memref<64x8x8x1xsi8>, memref<64x2xsi64>) -> memref<12x57x57x64xsi8>
%3 = "conv"(%arg0, %1, %0) ({}) {} : (memref<12x64x64x64xsi8>, memref<64x8x8x1xsi8>, memref<64x2xsi64>) -> memref<12x57x57x64xsi8>
%4 = "eltwise"(%2, %3) ({
}) {} : (memref<12x57x57x64xsi8>, memref<12x57x57x64xsi8>) -> memref<12x57x57x64xsi8>
return %4 : memref<12x57x57x64xsi8>
}`
These two conv ops have an empty region, so they will be not able to be estimated by current CSE Pass.
In fact, these two Ops are identical because they have the same functionality and attributes,and also have the same region(which are empty).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVcGOozgQ_RpzKXVkTIBw4NBNOrtzmtXsSns2UATPGBtRppP8_coOoZPW7E6fV4pAiuvVe8-FXkkidTSIJUtfWLqP5Ox6O5W_nZU07SWqbXspf1cgtWaiYnzP-PPfPRqYSZkjVH--wii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