[Mlir-commits] [flang] [mlir] [mlir][CSE] Introduce hoist-pure-ops logic to CSE pass (PR #180556)
lonely eagle
llvmlistbot at llvm.org
Wed Apr 1 03:49:44 PDT 2026
================
----------------
linuxlonelyeagle wrote:
There is a example:
```
func.func @cse_multiple_regions(%c: i1, %t: tensor<5xf32>) -> (tensor<5xf32>, tensor<5xf32>) {
%r1 = scf.if %c -> (tensor<5xf32>) {
%0 = tensor.empty() : tensor<5xf32>
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
%r2 = scf.if %c -> (tensor<5xf32>) {
%0 = tensor.empty() : tensor<5xf32>
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
return %r1, %r2 : tensor<5xf32>, tensor<5xf32>
}
```
if we don't host `op`, if will be
```
%0 = tensor.empty() : tensor<5xf32>
%r1 = scf.if %c -> (tensor<5xf32>) {
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
%r2 = scf.if %c -> (tensor<5xf32>) {
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
return %r1, %r2 : tensor<5xf32>, tensor<5xf32>
}
```
That's because it happens before deleting all the dead operations.It will be
```
%0 = tensor.empty() : tensor<5xf32> //`exiting`
%r1 = scf.if %c -> (tensor<5xf32>) {
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
%r2 = scf.if %c -> (tensor<5xf32>) {
%1 = tensor.empty() : tensor<5xf32> // `op`
scf.yield %0 : tensor<5xf32>
} else {
scf.yield %t : tensor<5xf32>
}
return %r1, %r2 : tensor<5xf32>, tensor<5xf32>
}
```
https://github.com/llvm/llvm-project/pull/180556
More information about the Mlir-commits
mailing list