-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[flang][OpenMP] Fix firstprivate not working with lastprivate in DO SIMD #170163
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
+151
−23
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
48 changes: 48 additions & 0 deletions
48
flang/test/Integration/OpenMP/do-simd-firstprivate-lastprivate-runtime.f90
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,48 @@ | ||
| ! Test runtime behavior of DO SIMD with firstprivate and lastprivate on same variable | ||
| ! This is the reproducer from issue #168306 | ||
|
|
||
| ! REQUIRES: openmp-runtime | ||
|
|
||
| ! RUN: %flang_fc1 -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM | ||
| ! RUN: %flang -fopenmp %s -o %t && %t | FileCheck %s | ||
|
|
||
| ! LLVM-LABEL: define {{.*}} @_QQmain | ||
| program main | ||
| integer :: a | ||
| integer :: i | ||
|
|
||
| a = 10 | ||
| !$omp do simd lastprivate(a) firstprivate(a) | ||
| do i = 1, 1 | ||
| ! Inside loop: a should be 10 (from firstprivate initialization) | ||
| ! CHECK: main1 : a = 10 | ||
| print *, "main1 : a = ", a | ||
| a = 20 | ||
| end do | ||
| !$omp end do simd | ||
| ! After loop: a should be 20 (from lastprivate copy-out) | ||
| ! CHECK: main2 : a = 20 | ||
| print *, "main2 : a = ", a | ||
|
|
||
| call sub | ||
| ! CHECK: pass | ||
| print *, 'pass' | ||
| end program main | ||
|
|
||
| subroutine sub | ||
| integer :: a | ||
| integer :: i | ||
|
|
||
| a = 10 | ||
| !$omp do simd lastprivate(a) firstprivate(a) | ||
| do i = 1, 1 | ||
| ! Inside loop: a should be 10 (from firstprivate initialization) | ||
| ! CHECK: sub1 : a = 10 | ||
| print *, "sub1 : a = ", a | ||
| a = 20 | ||
| end do | ||
| !$omp end do simd | ||
| ! After loop: a should be 20 (from lastprivate copy-out) | ||
| ! CHECK: sub2 : a = 20 | ||
| print *, "sub2 : a = ", a | ||
| end subroutine sub |
85 changes: 85 additions & 0 deletions
85
flang/test/Lower/OpenMP/do-simd-firstprivate-lastprivate.f90
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,85 @@ | ||
| ! Test for DO SIMD with the same variable in both firstprivate and lastprivate clauses | ||
| ! This tests the fix for issue #168306 | ||
|
|
||
| ! RUN: %flang_fc1 -fopenmp -mmlir --enable-delayed-privatization-staging=true -emit-hlfir %s -o - | FileCheck %s | ||
|
|
||
| ! Test case 1: Basic test with firstprivate + lastprivate on same variable | ||
| ! CHECK-LABEL: func.func @_QPdo_simd_first_last_same_var | ||
| subroutine do_simd_first_last_same_var() | ||
| integer :: a | ||
| integer :: i | ||
| a = 10 | ||
|
|
||
| ! CHECK: omp.wsloop | ||
| ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]], @{{.*}}private{{.*}} %{{.*}} -> %[[PRIV_I:.*]] : !fir.ref<i32>, !fir.ref<i32>) | ||
| ! CHECK-NEXT: omp.simd | ||
| ! CHECK-NEXT: omp.loop_nest (%[[IV:.*]]) : i32 | ||
| !$omp do simd firstprivate(a) lastprivate(a) | ||
| do i = 1, 1 | ||
| ! CHECK: %[[FIRSTPRIV_A_DECL:.*]]:2 = hlfir.declare %[[FIRSTPRIV_A]] | ||
| ! CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I]] | ||
| ! The private copy should be initialized from firstprivate (value 10) | ||
| ! and then modified to 20 | ||
| a = 20 | ||
| end do | ||
| !$omp end do simd | ||
| ! After the loop, 'a' should be 20 due to lastprivate | ||
| end subroutine do_simd_first_last_same_var | ||
|
|
||
| ! Test case 2: Test with lastprivate and firstprivate in reverse order | ||
| ! CHECK-LABEL: func.func @_QPdo_simd_last_first_reverse | ||
| subroutine do_simd_last_first_reverse() | ||
| integer :: a | ||
| integer :: i | ||
| a = 10 | ||
|
|
||
| ! CHECK: omp.wsloop | ||
| ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]], @{{.*}}private{{.*}} %{{.*}} -> %[[PRIV_I:.*]] : !fir.ref<i32>, !fir.ref<i32>) | ||
| ! CHECK-NEXT: omp.simd | ||
| !$omp do simd lastprivate(a) firstprivate(a) | ||
| do i = 1, 1 | ||
| a = 20 | ||
| end do | ||
| !$omp end do simd | ||
| end subroutine do_simd_last_first_reverse | ||
|
|
||
| ! Test case 3: Multiple variables with mixed privatization | ||
| ! CHECK-LABEL: func.func @_QPdo_simd_multiple_vars | ||
| subroutine do_simd_multiple_vars() | ||
| integer :: a, b, c | ||
| integer :: i | ||
| a = 10 | ||
| b = 20 | ||
| c = 30 | ||
|
|
||
| ! CHECK: omp.wsloop | ||
| ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %{{.*}}, @{{.*}}firstprivate{{.*}} %{{.*}} -> %{{.*}}, @{{.*}}private{{.*}} %{{.*}} -> %{{.*}} : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) | ||
| ! CHECK-NEXT: omp.simd | ||
| !$omp do simd firstprivate(a, b) lastprivate(a) private(c) | ||
| do i = 1, 5 | ||
| a = a + 1 | ||
| b = b + 1 | ||
| c = i | ||
| end do | ||
| !$omp end do simd | ||
| end subroutine do_simd_multiple_vars | ||
|
|
||
| ! Test case 4: Reproducer from issue #168306 | ||
| ! CHECK-LABEL: func.func @_QPissue_168306_reproducer | ||
| subroutine issue_168306_reproducer() | ||
| integer :: a | ||
| integer :: i | ||
| a = 10 | ||
|
|
||
| ! CHECK: omp.wsloop | ||
| ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]], @{{.*}}private{{.*}} %{{.*}} -> %[[PRIV_I:.*]] : !fir.ref<i32>, !fir.ref<i32>) | ||
| ! CHECK-NEXT: omp.simd | ||
| !$omp do simd lastprivate(a) firstprivate(a) | ||
| do i = 1, 1 | ||
| ! Inside the loop, 'a' should start at 10 (from firstprivate) | ||
| ! This is the key behavior that was broken | ||
| a = 20 | ||
| end do | ||
| !$omp end do simd | ||
| ! After the loop, 'a' should be 20 (from lastprivate) | ||
| end subroutine issue_168306_reproducer | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.