-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][OpenMP] Fix LASTPRIVATE for iteration variables #69773
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
! Test LASTPRIVATE with iteration variable. | ||
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s | ||
|
||
!CHECK-LABEL: func @_QPlastprivate_iv_inc | ||
!CHECK: %[[I_MEM:.*]] = fir.alloca i32 {adapt.valuebyref, pinned} | ||
!CHECK: %[[I:.*]]:2 = hlfir.declare %[[I_MEM]] {uniq_name = "_QFlastprivate_iv_incEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
!CHECK: %[[I2_MEM:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlastprivate_iv_incEi"} | ||
!CHECK: %[[I2:.*]]:2 = hlfir.declare %[[I2_MEM]] {uniq_name = "_QFlastprivate_iv_incEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
!CHECK: %[[LB:.*]] = arith.constant 4 : i32 | ||
!CHECK: %[[UB:.*]] = arith.constant 10 : i32 | ||
!CHECK: %[[STEP:.*]] = arith.constant 3 : i32 | ||
!CHECK: omp.wsloop for (%[[IV:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) { | ||
!CHECK: fir.store %[[IV]] to %[[I]]#1 : !fir.ref<i32> | ||
!CHECK: %[[V:.*]] = arith.addi %[[IV]], %[[STEP]] : i32 | ||
!CHECK: %[[C0:.*]] = arith.constant 0 : i32 | ||
!CHECK: %[[STEP_NEG:.*]] = arith.cmpi slt, %[[STEP]], %[[C0]] : i32 | ||
!CHECK: %[[V_LT:.*]] = arith.cmpi slt, %[[V]], %[[UB]] : i32 | ||
!CHECK: %[[V_GT:.*]] = arith.cmpi sgt, %[[V]], %[[UB]] : i32 | ||
!CHECK: %[[CMP:.*]] = arith.select %[[STEP_NEG]], %[[V_LT]], %[[V_GT]] : i1 | ||
!CHECK: fir.if %[[CMP]] { | ||
!CHECK: fir.store %[[V]] to %[[I]]#1 : !fir.ref<i32> | ||
!CHECK: %[[I_VAL:.*]] = fir.load %[[I]]#0 : !fir.ref<i32> | ||
!CHECK: hlfir.assign %[[I_VAL]] to %[[I2]]#0 temporary_lhs : i32, !fir.ref<i32> | ||
!CHECK: } | ||
!CHECK: omp.yield | ||
!CHECK: } | ||
subroutine lastprivate_iv_inc() | ||
integer :: i | ||
|
||
!$omp do lastprivate(i) | ||
do i = 4, 10, 3 | ||
end do | ||
!$omp end do | ||
end subroutine | ||
|
||
!CHECK-LABEL: func @_QPlastprivate_iv_dec | ||
!CHECK: %[[I_MEM:.*]] = fir.alloca i32 {adapt.valuebyref, pinned} | ||
!CHECK: %[[I:.*]]:2 = hlfir.declare %[[I_MEM]] {uniq_name = "_QFlastprivate_iv_decEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
!CHECK: %[[I2_MEM:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlastprivate_iv_decEi"} | ||
!CHECK: %[[I2:.*]]:2 = hlfir.declare %[[I2_MEM]] {uniq_name = "_QFlastprivate_iv_decEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
!CHECK: %[[LB:.*]] = arith.constant 10 : i32 | ||
!CHECK: %[[UB:.*]] = arith.constant 1 : i32 | ||
!CHECK: %[[STEP:.*]] = arith.constant -3 : i32 | ||
!CHECK: omp.wsloop for (%[[IV:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) { | ||
!CHECK: fir.store %[[IV]] to %[[I]]#1 : !fir.ref<i32> | ||
!CHECK: %[[V:.*]] = arith.addi %[[IV]], %[[STEP]] : i32 | ||
!CHECK: %[[C0:.*]] = arith.constant 0 : i32 | ||
!CHECK: %[[STEP_NEG:.*]] = arith.cmpi slt, %[[STEP]], %[[C0]] : i32 | ||
!CHECK: %[[V_LT:.*]] = arith.cmpi slt, %[[V]], %[[UB]] : i32 | ||
!CHECK: %[[V_GT:.*]] = arith.cmpi sgt, %[[V]], %[[UB]] : i32 | ||
!CHECK: %[[CMP:.*]] = arith.select %[[STEP_NEG]], %[[V_LT]], %[[V_GT]] : i1 | ||
!CHECK: fir.if %[[CMP]] { | ||
!CHECK: fir.store %[[V]] to %[[I]]#1 : !fir.ref<i32> | ||
!CHECK: %[[I_VAL:.*]] = fir.load %[[I]]#0 : !fir.ref<i32> | ||
!CHECK: hlfir.assign %[[I_VAL]] to %[[I2]]#0 temporary_lhs : i32, !fir.ref<i32> | ||
!CHECK: } | ||
!CHECK: omp.yield | ||
!CHECK: } | ||
subroutine lastprivate_iv_dec() | ||
integer :: i | ||
|
||
!$omp do lastprivate(i) | ||
do i = 10, 1, -3 | ||
end do | ||
!$omp end do | ||
end subroutine |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: An additional
fit.store
here is redundant. We expect all last private operations to be abstracted within^%lpv_update_blk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
fir.store
here is needed. Considering the example of the previous conversation,loopIV
is updated in the beginning of the loop body only, to have the same value asiv
, but we need it to holdv
instead (iv
+step
). Also,^%lpv_update_blk
copiesloopIV
toia
and notiv
toloopIV
. In the end this store gets optimized, because^%lpv_update_blk
generates a loadloopIV
right after it.