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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Sep 10 17:02:53 PDT 2023


shraiysh wrote:

>If an optimization makes a change that violates the invariant will the compiler assert?

Yes, that will be a compilation failure. @Meinersbur would it be okay if we do loop transforms within MLIR in the very beginning to avoid such optimization issues? I understand that it is not in line with the aim of using OpenMPIRBuilder for common OpenMP stuff, but it would ensure correctness.

> I also had another question. Is legal OpenMP?
> 
> ```int x = 5;
> #pragma omp unroll full
> for (i = 0; i < 10; i++) {
>   x = x + 1;
> }
> return x;```
> Would this be represented as a canonical loop, and what would the MLIR for it look like?
Not sure if it is legal, but if legal, then the transformed MLIR would be
```
%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"}
```

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


More information about the Mlir-commits mailing list