Skip to content

Commit ffd9374

Browse files
committed
Fix tests and limit the nesting of construct to only tiling.
1 parent bd8edf7 commit ffd9374

File tree

7 files changed

+33
-24
lines changed

7 files changed

+33
-24
lines changed

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,32 @@ class CanonicalizationOfOmp {
133133
// Ignore compiler directives.
134134
if (GetConstructIf<parser::CompilerDirective>(*nextIt))
135135
continue;
136-
137136
// Keep track of the loops to handle the end loop directives
138137
std::stack<parser::OpenMPLoopConstruct *> loops;
139138
loops.push(&x);
140-
while (auto *innerConstruct{
139+
if (auto *innerConstruct{
141140
GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
142141
if (auto *innerOmpLoop{
143142
std::get_if<parser::OpenMPLoopConstruct>(&innerConstruct->u)}) {
144-
std::get<
145-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
146-
loops.top()->t) = std::move(*innerOmpLoop);
147-
// Retrieveing the address so that DoConstruct or inner loop can be
148-
// set later.
149-
loops.push(&(std::get<std::optional<
150-
common::Indirection<parser::OpenMPLoopConstruct>>>(
151-
loops.top()->t)
152-
.value()
153-
.value()));
154-
nextIt = block.erase(nextIt);
143+
auto &innerBeginDir{
144+
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
145+
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
146+
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
147+
std::get<std::optional<
148+
common::Indirection<parser::OpenMPLoopConstruct>>>(
149+
loops.top()->t) = std::move(*innerOmpLoop);
150+
// Retrieveing the address so that DoConstruct or inner loop can be
151+
// set later.
152+
loops.push(&(std::get<std::optional<
153+
common::Indirection<parser::OpenMPLoopConstruct>>>(
154+
loops.top()->t)
155+
.value()
156+
.value()));
157+
nextIt = block.erase(nextIt);
158+
}
155159
}
156160
}
161+
157162
if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
158163
if (doCons->GetLoopControl()) {
159164
std::get<std::optional<parser::DoConstruct>>(loops.top()->t) =
@@ -167,6 +172,9 @@ class CanonicalizationOfOmp {
167172
loops.top()->t) = std::move(*endDir);
168173
nextIt = block.erase(nextIt);
169174
loops.pop();
175+
} else {
176+
// If there is a mismatch bail out.
177+
break;
170178
}
171179
}
172180
} else {

flang/test/Lower/OpenMP/parallel-wsloop-lastpriv.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ subroutine omp_do_lastprivate_collapse2(a)
108108
! CHECK-NEXT: %[[UB2:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<i32>
109109
! CHECK-NEXT: %[[STEP2:.*]] = arith.constant 1 : i32
110110
! CHECK-NEXT: omp.wsloop private(@{{.*}} %{{.*}}#0 -> %[[A_PVT_REF:.*]], @{{.*}} %{{.*}}#0 -> %[[I_PVT_REF:.*]], @{{.*}} %{{.*}}#0 -> %[[J_PVT_REF:.*]] : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) {
111-
! CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]], %[[ARG2:.*]]) : i32 = (%[[LB1]], %[[LB2]]) to (%[[UB1]], %[[UB2]]) inclusive step (%[[STEP1]], %[[STEP2]]) {
111+
! CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]], %[[ARG2:.*]]) : i32 = (%[[LB1]], %[[LB2]]) to (%[[UB1]], %[[UB2]]) inclusive step (%[[STEP1]], %[[STEP2]]) collapse(2) {
112112
! CHECK: %[[A_PVT_DECL:.*]]:2 = hlfir.declare %[[A_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse2Ea"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
113113
! CHECK: %[[I_PVT_DECL:.*]]:2 = hlfir.declare %[[I_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse2Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
114114
! CHECK: %[[J_PVT_DECL:.*]]:2 = hlfir.declare %[[J_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse2Ej"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
@@ -174,7 +174,7 @@ subroutine omp_do_lastprivate_collapse3(a)
174174
! CHECK-NEXT: %[[UB3:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<i32>
175175
! CHECK-NEXT: %[[STEP3:.*]] = arith.constant 1 : i32
176176
! CHECK-NEXT: omp.wsloop private(@{{.*}} %{{.*}}#0 -> %[[A_PVT_REF:.*]], @{{.*}} %{{.*}}#0 -> %[[I_PVT_REF:.*]], @{{.*}} %{{.*}}#0 -> %[[J_PVT_REF:.*]], @{{.*}} %{{.*}}#0 -> %[[K_PVT_REF:.*]] : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) {
177-
! CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]], %[[ARG2:.*]], %[[ARG3:.*]]) : i32 = (%[[LB1]], %[[LB2]], %[[LB3]]) to (%[[UB1]], %[[UB2]], %[[UB3]]) inclusive step (%[[STEP1]], %[[STEP2]], %[[STEP3]]) {
177+
! CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]], %[[ARG2:.*]], %[[ARG3:.*]]) : i32 = (%[[LB1]], %[[LB2]], %[[LB3]]) to (%[[UB1]], %[[UB2]], %[[UB3]]) inclusive step (%[[STEP1]], %[[STEP2]], %[[STEP3]]) collapse(3) {
178178
! CHECK: %[[A_PVT_DECL:.*]]:2 = hlfir.declare %[[A_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse3Ea"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
179179
! CHECK: %[[I_PVT_DECL:.*]]:2 = hlfir.declare %[[I_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse3Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
180180
! CHECK: %[[J_PVT_DECL:.*]]:2 = hlfir.declare %[[J_PVT_REF]] {uniq_name = "_QFomp_do_lastprivate_collapse3Ej"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)

flang/test/Lower/OpenMP/simd.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ subroutine simd_with_collapse_clause(n)
175175
! CHECK-NEXT: omp.loop_nest (%[[ARG_0:.*]], %[[ARG_1:.*]]) : i32 = (
176176
! CHECK-SAME: %[[LOWER_I]], %[[LOWER_J]]) to (
177177
! CHECK-SAME: %[[UPPER_I]], %[[UPPER_J]]) inclusive step (
178-
! CHECK-SAME: %[[STEP_I]], %[[STEP_J]]) {
178+
! CHECK-SAME: %[[STEP_I]], %[[STEP_J]]) collapse(2) {
179179
!$OMP SIMD COLLAPSE(2)
180180
do i = 1, n
181181
do j = 1, n

flang/test/Lower/OpenMP/wsloop-variable.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ program wsloop_variable
2323
!CHECK: %[[TMP6:.*]] = fir.convert %[[TMP1]] : (i32) -> i64
2424
!CHECK: %[[TMP7:.*]] = fir.convert %{{.*}} : (i32) -> i64
2525
!CHECK: omp.wsloop private({{.*}}) {
26-
!CHECK-NEXT: omp.loop_nest (%[[ARG0:.*]], %[[ARG1:.*]]) : i64 = (%[[TMP2]], %[[TMP5]]) to (%[[TMP3]], %[[TMP6]]) inclusive step (%[[TMP4]], %[[TMP7]]) {
26+
!CHECK-NEXT: omp.loop_nest (%[[ARG0:.*]], %[[ARG1:.*]]) : i64 = (%[[TMP2]], %[[TMP5]]) to (%[[TMP3]], %[[TMP6]]) inclusive step (%[[TMP4]], %[[TMP7]]) collapse(2) {
2727
!CHECK: %[[ARG0_I16:.*]] = fir.convert %[[ARG0]] : (i64) -> i16
2828
!CHECK: hlfir.assign %[[ARG0_I16]] to %[[STORE_IV0:.*]]#0 : i16, !fir.ref<i16>
2929
!CHECK: hlfir.assign %[[ARG1]] to %[[STORE_IV1:.*]]#0 : i64, !fir.ref<i64>

flang/test/Semantics/OpenMP/do-collapse.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ program omp_doCollapse
3131
end do
3232
end do
3333

34+
!ERROR: The value of the parameter in the COLLAPSE or ORDERED clause must not be larger than the number of nested loops following the construct.
3435
!ERROR: At most one COLLAPSE clause can appear on the SIMD directive
3536
!$omp simd collapse(2) collapse(1)
3637
do i = 1, 4

mlir/test/Target/LLVMIR/omptarget-wsloop-collapsed.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
99
%loop_lb = llvm.mlir.constant(0 : i32) : i32
1010
%loop_step = llvm.mlir.constant(1 : index) : i32
1111
omp.wsloop {
12-
omp.loop_nest (%arg1, %arg2) : i32 = (%loop_lb, %loop_lb) to (%loop_ub, %loop_ub) inclusive step (%loop_step, %loop_step) {
12+
omp.loop_nest (%arg1, %arg2) : i32 = (%loop_lb, %loop_lb) to (%loop_ub, %loop_ub) inclusive step (%loop_step, %loop_step) collapse(2) {
1313
%1 = llvm.add %arg1, %arg2 : i32
1414
%2 = llvm.mul %arg2, %loop_ub overflow<nsw> : i32
1515
%3 = llvm.add %arg1, %2 :i32

mlir/test/Target/LLVMIR/openmp-llvm.mlir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ llvm.func @simd_simple(%lb : i64, %ub : i64, %step : i64, %arg0: !llvm.ptr) {
786786
// CHECK-LABEL: @simd_simple_multiple
787787
llvm.func @simd_simple_multiple(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : i64, %ub2 : i64, %step2 : i64, %arg0: !llvm.ptr, %arg1: !llvm.ptr) {
788788
omp.simd {
789-
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) inclusive step (%step1, %step2) {
789+
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) inclusive step (%step1, %step2) collapse(2) {
790790
%3 = llvm.mlir.constant(2.000000e+00 : f32) : f32
791791
// The form of the emitted IR is controlled by OpenMPIRBuilder and
792792
// tested there. Just check that the right metadata is added and collapsed
@@ -824,7 +824,7 @@ llvm.func @simd_simple_multiple(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : i64
824824
// CHECK-LABEL: @simd_simple_multiple_simdlen
825825
llvm.func @simd_simple_multiple_simdlen(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : i64, %ub2 : i64, %step2 : i64, %arg0: !llvm.ptr, %arg1: !llvm.ptr) {
826826
omp.simd simdlen(2) {
827-
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) {
827+
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) collapse(2) {
828828
%3 = llvm.mlir.constant(2.000000e+00 : f32) : f32
829829
// The form of the emitted IR is controlled by OpenMPIRBuilder and
830830
// tested there. Just check that the right metadata is added.
@@ -848,7 +848,7 @@ llvm.func @simd_simple_multiple_simdlen(%lb1 : i64, %ub1 : i64, %step1 : i64, %l
848848
// CHECK-LABEL: @simd_simple_multiple_safelen
849849
llvm.func @simd_simple_multiple_safelen(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : i64, %ub2 : i64, %step2 : i64, %arg0: !llvm.ptr, %arg1: !llvm.ptr) {
850850
omp.simd safelen(2) {
851-
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) {
851+
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) collapse(2) {
852852
%3 = llvm.mlir.constant(2.000000e+00 : f32) : f32
853853
%4 = llvm.getelementptr %arg0[%iv1] : (!llvm.ptr, i64) -> !llvm.ptr, f32
854854
%5 = llvm.getelementptr %arg1[%iv2] : (!llvm.ptr, i64) -> !llvm.ptr, f32
@@ -867,7 +867,7 @@ llvm.func @simd_simple_multiple_safelen(%lb1 : i64, %ub1 : i64, %step1 : i64, %l
867867
// CHECK-LABEL: @simd_simple_multiple_simdlen_safelen
868868
llvm.func @simd_simple_multiple_simdlen_safelen(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : i64, %ub2 : i64, %step2 : i64, %arg0: !llvm.ptr, %arg1: !llvm.ptr) {
869869
omp.simd simdlen(1) safelen(2) {
870-
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) {
870+
omp.loop_nest (%iv1, %iv2) : i64 = (%lb1, %lb2) to (%ub1, %ub2) step (%step1, %step2) collapse(2) {
871871
%3 = llvm.mlir.constant(2.000000e+00 : f32) : f32
872872
%4 = llvm.getelementptr %arg0[%iv1] : (!llvm.ptr, i64) -> !llvm.ptr, f32
873873
%5 = llvm.getelementptr %arg1[%iv2] : (!llvm.ptr, i64) -> !llvm.ptr, f32
@@ -1267,7 +1267,7 @@ llvm.func @collapse_wsloop(
12671267
// CHECK: store i32 %[[TOTAL_SUB_1]], ptr
12681268
// CHECK: call void @__kmpc_for_static_init_4u
12691269
omp.wsloop {
1270-
omp.loop_nest (%arg0, %arg1, %arg2) : i32 = (%0, %1, %2) to (%3, %4, %5) step (%6, %7, %8) {
1270+
omp.loop_nest (%arg0, %arg1, %arg2) : i32 = (%0, %1, %2) to (%3, %4, %5) step (%6, %7, %8) collapse(3) {
12711271
%31 = llvm.load %20 : !llvm.ptr -> i32
12721272
%32 = llvm.add %31, %arg0 : i32
12731273
%33 = llvm.add %32, %arg1 : i32
@@ -1329,7 +1329,7 @@ llvm.func @collapse_wsloop_dynamic(
13291329
// CHECK: store i32 %[[TOTAL]], ptr
13301330
// CHECK: call void @__kmpc_dispatch_init_4u
13311331
omp.wsloop schedule(dynamic) {
1332-
omp.loop_nest (%arg0, %arg1, %arg2) : i32 = (%0, %1, %2) to (%3, %4, %5) step (%6, %7, %8) {
1332+
omp.loop_nest (%arg0, %arg1, %arg2) : i32 = (%0, %1, %2) to (%3, %4, %5) step (%6, %7, %8) collapse(3) {
13331333
%31 = llvm.load %20 : !llvm.ptr -> i32
13341334
%32 = llvm.add %31, %arg0 : i32
13351335
%33 = llvm.add %32, %arg1 : i32

0 commit comments

Comments
 (0)