[Mlir-commits] [mlir] [OpenMP Dialect] Add omp.canonical_loop operation. (PR #65380)

Jan Leyonberg llvmlistbot at llvm.org
Mon Sep 11 06:45:58 PDT 2023


jsjodin wrote:

Could an optimization that handles loads/stores potentially transform:
 
 ```
 %x = llvm.alloca i32
 llvm.store i32 5, %x
 %cli = omp.canonical_loop {
   omp.structured_region {
      %x1 = llvm.load %x -> i32
     %add1 = arith.add %x1, 1
     llvm.store %add1, %x
     omp.yield
   }
   omp.yield
 }
 omp.unroll(%cli) {"unroll_type"="full"}
  %x2 = llvm.load %x -> i32
  func.return %x2
> ```

into:
 ```
 %x = llvm.alloca i32
 llvm.store i32 5, %x
 %cli = omp.canonical_loop {
   omp.structured_region {
     llvm.store 6, %x
     omp.yield
   }
   omp.yield
 }
 omp.unroll(%cli) {"unroll_type"="full"}
  %x2 = llvm.load %x -> i32
  func.return %x2
```
My concern is that there is an implicit loop that is not visible, any kind of mem2reg type of transform could potentially be wrong. There is a similar discussion regarding CSE, which could also be an issue here, meaning the add could be hoisted or folded out of the canonical_loop. To add these kinds of operations where the regions change the execution mode in some way e.g. changing target, multi-threading, implicit loops etc. we have to go through the analyses and optimizations and improve/add interfaces so that these ops are handled correctly.


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


More information about the Mlir-commits mailing list