diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -125,7 +125,7 @@ }]; } -def TerminatorOp : OpenMP_Op<"terminator", [Terminator]> { +def TerminatorOp : OpenMP_Op<"terminator", [Terminator, NoSideEffect]> { let summary = "terminator for OpenMP regions"; let description = [{ A terminator operation for regions that appear in the body of OpenMP diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir --- a/mlir/test/Dialect/OpenMP/canonicalize.mlir +++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir @@ -72,3 +72,57 @@ // CHECK-LABEL: func.func @update_unnecessary_computations // CHECK-NOT: omp.atomic.update // CHECK: omp.atomic.write + +// ----- + +// CHECK-LABEL: func.func @parallel_empty +func.func @parallel_empty() { + omp.parallel {} + return +} + +// CHECK-NOT: omp.parallel + +// ----- + +// CHECK-LABEL: func.func @parallel_only_terminator +func.func @parallel_only_terminator() { + omp.parallel { + omp.terminator + } + return +} + +// CHECK-NOT: omp.parallel +// CHECK-NOT: omp.terminator + +// ----- + +// CHECK-LABEL: func.func @parallel_no_side_effects +func.func @parallel_no_side_effects(%a: i32, %b: i32) { + omp.parallel { + %x = arith.addi %a, %b : i32 + omp.terminator + } + return +} + +// CHECK-NOT: omp.parallel +// CHECK-NOT: omp.terminator + +// ----- + +// CHECK-LABEL: func.func @parallel_maybe_side_effects +func.func @parallel_maybe_side_effects(%a: i32, %b: i32) { + omp.parallel { + func.call @foo() : () -> () + omp.terminator + } + return +} + +func.func private @foo() -> () + +// CHECK: omp.parallel +// CHECK: func.call @foo() : () -> () +// CHECK: omp.terminator