[Mlir-commits] [mlir] [MLIR][OpenMP] Add omp.loop_nest operation (PR #87083)

Sergio Afonso llvmlistbot at llvm.org
Thu Apr 11 02:43:25 PDT 2024


skatrak wrote:

Yes, that's the constant hoisting part of the canonicalization pass. As per the documentation, it will hoist constants "into the entry block of the first parent barrier region". Which is an `IsolatedFromAbove` operation or one that implements the `DialectFoldInterface` returns `true` in `shouldMaterializeInto()`. Wrappers are not intended to do either of these things and I can confirm that constants for such cases are hoisted straight through them:
```mlir
func.func @constant_sink_test(%x : !llvm.ptr, %y : index) {
  omp.wsloop {
    omp.loop_nest (%i) : index = (%y) to (%y) step (%y) {
      %c1 = arith.constant 10 : i32
      llvm.store %c1, %x : i32, !llvm.ptr
      omp.yield
    }
    omp.terminator
  }
  return
}
```
mlir-opt --canonicalize test.mlir -o -
```mlir
func.func @constant_sink_test(%arg0: !llvm.ptr, %arg1: index) {
  %c10_i32 = arith.constant 10 : i32
  omp.wsloop {
    omp.loop_nest (%arg2) : index = (%arg1) to (%arg1) step (%arg1) {
      llvm.store %c10_i32, %arg0 : i32, !llvm.ptr
      omp.yield
    }
    omp.terminator
  }
  return
}
```

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


More information about the Mlir-commits mailing list