Skip to content

[OpenMP] Enable simd in non-reduction composite constructs #146097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2847,11 +2847,8 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
auto simdOp = cast<omp::SimdOp>(opInst);

// TODO: Replace this with proper composite translation support.
// Currently, simd information on composite constructs is ignored, so e.g.
// 'do/for simd' will be treated the same as a standalone 'do/for'. This is
// allowed by the spec, since it's equivalent to using a SIMD length of 1.
if (simdOp.isComposite()) {
// TODO: Replace this once simd + reduction is properly supported
if (simdOp.isComposite() && simdOp.getReductionByref().has_value()) {
if (failed(convertIgnoredWrapper(simdOp, moduleTranslation)))
return failure();

Expand Down
38 changes: 38 additions & 0 deletions mlir/test/Target/LLVMIR/openmp-parallel-do-simd.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s

// Check that omp.simd as a leaf of a composite construct still generates
// the appropriate loop vectorization attribute.

// CHECK-LABEL: define internal void @test_parallel_do_simd..omp_par
// CHECK: omp.par.entry:
// CHECK: omp.par.region:
// CHECK: omp_loop.header:
// CHECK: omp_loop.inc:
// CHECK-NEXT: %omp_loop.next = add nuw i32 %omp_loop.iv, 1
// CHECK-NEXT: br label %omp_loop.header, !llvm.loop ![[LOOP_ATTR:.*]]
// CHECK: ![[LOOP_ATTR]] = distinct !{![[LOOP_ATTR]], ![[LPAR:.*]], ![[LVEC:.*]]}
// CHECK: ![[LPAR]] = !{!"llvm.loop.parallel_accesses", ![[PAR_ACC:.*]]}
// CHECK: ![[LVEC]] = !{!"llvm.loop.vectorize.enable", i1 true}

llvm.func @test_parallel_do_simd() {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i32 {bindc_name = "i"} : (i64) -> !llvm.ptr
%2 = llvm.mlir.constant(1000 : i32) : i32
%3 = llvm.mlir.constant(1 : i32) : i32
%4 = llvm.mlir.constant(1 : i64) : i64
omp.parallel {
%5 = llvm.mlir.constant(1 : i64) : i64
%6 = llvm.alloca %5 x i32 {bindc_name = "i", pinned} : (i64) -> !llvm.ptr
%7 = llvm.mlir.constant(1 : i64) : i64
omp.wsloop {
omp.simd {
omp.loop_nest (%arg0) : i32 = (%3) to (%2) inclusive step (%3) {
llvm.store %arg0, %6 : i32, !llvm.ptr
omp.yield
}
} {omp.composite}
} {omp.composite}
omp.terminator
}
llvm.return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: mlir-translate --mlir-to-llvmir %s | FileCheck %s

// Check that omp.simd as a leaf of a composite construct still generates
// the appropriate loop vectorization attribute.

// CHECK-LABEL: define internal void @test_teams_distribute_parallel_do_simd..omp_par.2
// CHECK: teams.body:
// CHECK: omp.teams.region:

// CHECK-LABEL: define internal void @test_teams_distribute_parallel_do_simd..omp_par.1
// CHECK: omp.par.entry:
// CHECK: omp.par.region:
// CHECK: distribute.exit:

// CHECK-LABEL: define internal void @test_teams_distribute_parallel_do_simd..omp_par
// CHECK: distribute.body:
// CHECK: omp.distribute.region:
// CHECK: omp_loop.header:
// CHECK: omp_loop.inc:
// CHECK-NEXT: %omp_loop.next = add nuw i32 %omp_loop.iv, 1
// CHECK-NEXT: br label %omp_loop.header, !llvm.loop ![[LOOP_ATTR:.*]]

// CHECK: ![[LOOP_ATTR]] = distinct !{![[LOOP_ATTR]], ![[LPAR:.*]], ![[LVEC:.*]]}
// CHECK: ![[LPAR]] = !{!"llvm.loop.parallel_accesses", ![[PAR_ACC:.*]]}
// CHECK: ![[LVEC]] = !{!"llvm.loop.vectorize.enable", i1 true}

omp.private {type = private} @_QFEi_private_i32 : i32
llvm.func @test_teams_distribute_parallel_do_simd() {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i32 {bindc_name = "i"} : (i64) -> !llvm.ptr
%2 = llvm.mlir.constant(1000 : i32) : i32
%3 = llvm.mlir.constant(1 : i32) : i32
%4 = llvm.mlir.constant(1 : i64) : i64
omp.teams {
omp.parallel {
omp.distribute {
omp.wsloop {
omp.simd private(@_QFEi_private_i32 %1 -> %arg0 : !llvm.ptr) {
omp.loop_nest (%arg1) : i32 = (%3) to (%2) inclusive step (%3) {
llvm.store %arg1, %arg0 : i32, !llvm.ptr
omp.yield
}
} {omp.composite}
} {omp.composite}
} {omp.composite}
omp.terminator
} {omp.composite}
omp.terminator
}
llvm.return
}
14 changes: 0 additions & 14 deletions mlir/test/Target/LLVMIR/openmp-todo.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ llvm.func @atomic_hint(%v : !llvm.ptr, %x : !llvm.ptr, %expr : i32) {

// -----

llvm.func @do_simd(%lb : i32, %ub : i32, %step : i32) {
omp.wsloop {
// expected-warning@below {{simd information on composite construct discarded}}
omp.simd {
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
omp.yield
}
} {omp.composite}
} {omp.composite}
llvm.return
}

// -----

llvm.func @distribute_allocate(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
// expected-error@below {{not yet implemented: Unhandled clause allocate in omp.distribute operation}}
// expected-error@below {{LLVM Translation failed for operation: omp.distribute}}
Expand Down
Loading