-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Flang][OpenMP] Support lowering of simd reductions #112194
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s | ||
! RUN: bbc -hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s | ||
|
||
!CHECK: omp.declare_reduction @[[REDUCER:.*]] : i32 | ||
|
||
!CHECK-LABEL: func @_QPsimd() | ||
subroutine simd | ||
integer :: i | ||
|
@@ -274,3 +276,25 @@ subroutine lastprivate_with_simd | |
sum = i + 1 | ||
end do | ||
end subroutine | ||
|
||
!CHECK-LABEL: func @_QPsimd_with_reduction_clause() | ||
subroutine simd_with_reduction_clause | ||
integer :: i, x | ||
x = 0 | ||
! CHECK: %[[LB:.*]] = arith.constant 1 : i32 | ||
! CHECK-NEXT: %[[UB:.*]] = arith.constant 9 : i32 | ||
! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32 | ||
! CHECK-NEXT: omp.simd reduction(@[[REDUCER]] %[[X:.*]]#0 -> %[[X_RED:.*]] : !fir.ref<i32>) { | ||
! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) { | ||
!$omp simd reduction(+:x) | ||
do i=1, 9 | ||
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X_RED]] {uniq_name = "_QFsimd_with_reduction_clauseEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this PR, but reading the full IR locally it looks like the loop iteration variable was not privatized. As I understand it, OpenMP 5.2 section 5.1.1 line 16 seems to say that it should be implicitly lastprivate. Did I miss something here? If not I'll create an issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I think the previous statement in the spec is the one that applies, since it has a single associated loop. So I guess it should actually be linear with a linear-step equal to the increment of the loop. But I believe you're right, since neither that nor lastprivatization in the case of multiple associated loops seem to be currently implemented. |
||
! CHECK: %[[X_LD:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32> | ||
! CHECK: %[[I_LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32> | ||
! CHECK: %[[SUM:.*]] = arith.addi %[[X_LD]], %[[I_LD]] : i32 | ||
! CHECK: hlfir.assign %[[SUM]] to %[[X_DECL]]#0 : i32, !fir.ref<i32> | ||
x = x+i | ||
end do | ||
!$OMP end simd | ||
end subroutine |
Uh oh!
There was an error while loading. Please reload this page.