[Mlir-commits] [mlir] [mlir][async]: Make async.execute operation pure (PR #116544)

Aviad Cohen llvmlistbot at llvm.org
Sun Nov 17 22:36:44 PST 2024


AviadCo wrote:

> Can you elaborate on the motivation and the correctness in the description of this PR please? This is surprising to me and I don't quite understand why this op can be Pure at the moment. Thanks.

Sure, the case I have is `scf.if` with result which means that I must have an `else` region. For example:
```
     %res = scf.if cond -> (!async.token) {
      ...
    } else {
      %token = async.execute {
        async.yield
      }
      scf.yield %token : !async.token
    }
```

In some phase, I reach the point where the `async` is being inside `if` that has no longer have result, for example:
```
    scf.if cond {
      ...
      %token = async.execute {
          .....
      }
      // Token is being used
    } else {
      async.execute {
        async.yield
      }
    }
```

In this case, I would expect that the whole `else` will be eliminated (folder) as the execute has no memory effect inside it and has no users. With `Pure` this will be optimized to:
```
    scf.if cond {
        %token = async.execute {
            .....
        }
        // Token is being used
    }
```

Keeping my specific flow apart, it seems legic to remove the execute region if it has no usages and have no memory effects like `scf.for` does.

https://github.com/llvm/llvm-project/pull/116544


More information about the Mlir-commits mailing list