|
| 1 | +! Test for DO SIMD with the same variable in both firstprivate and lastprivate clauses |
| 2 | +! This tests the fix for issue #168306 |
| 3 | + |
| 4 | +! RUN: %flang_fc1 -fopenmp -mmlir --openmp-enable-delayed-privatization-staging=true -emit-hlfir %s -o - | FileCheck %s |
| 5 | + |
| 6 | +! Test case 1: Basic test with firstprivate + lastprivate on same variable |
| 7 | +! CHECK-LABEL: func.func @_QPdo_simd_first_last_same_var |
| 8 | +subroutine do_simd_first_last_same_var() |
| 9 | + integer :: a |
| 10 | + integer :: i |
| 11 | + a = 10 |
| 12 | + |
| 13 | + ! CHECK: omp.wsloop |
| 14 | + ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]] : !fir.ref<i32>) |
| 15 | + ! CHECK-NEXT: omp.simd |
| 16 | + ! CHECK-SAME: private(@{{.*}} %{{.*}} -> %[[PRIV_A:.*]], @{{.*}} %{{.*}} -> %[[PRIV_I:.*]] : !fir.ref<i32>, !fir.ref<i32>) |
| 17 | + ! CHECK-NEXT: omp.loop_nest (%[[IV:.*]]) : i32 |
| 18 | + !$omp do simd firstprivate(a) lastprivate(a) |
| 19 | + do i = 1, 1 |
| 20 | + ! CHECK: %[[FIRSTPRIV_A_DECL:.*]]:2 = hlfir.declare %[[FIRSTPRIV_A]] |
| 21 | + ! CHECK: %[[PRIV_A_DECL:.*]]:2 = hlfir.declare %[[PRIV_A]] |
| 22 | + ! CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I]] |
| 23 | + ! The private copy should be initialized from firstprivate (value 10) |
| 24 | + ! and then modified to 20 |
| 25 | + a = 20 |
| 26 | + end do |
| 27 | + !$omp end do simd |
| 28 | + ! After the loop, 'a' should be 20 due to lastprivate |
| 29 | +end subroutine do_simd_first_last_same_var |
| 30 | + |
| 31 | +! Test case 2: Test with lastprivate and firstprivate in reverse order |
| 32 | +! CHECK-LABEL: func.func @_QPdo_simd_last_first_reverse |
| 33 | +subroutine do_simd_last_first_reverse() |
| 34 | + integer :: a |
| 35 | + integer :: i |
| 36 | + a = 10 |
| 37 | + |
| 38 | + ! CHECK: omp.wsloop |
| 39 | + ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]] : !fir.ref<i32>) |
| 40 | + ! CHECK-NEXT: omp.simd |
| 41 | + !$omp do simd lastprivate(a) firstprivate(a) |
| 42 | + do i = 1, 1 |
| 43 | + a = 20 |
| 44 | + end do |
| 45 | + !$omp end do simd |
| 46 | +end subroutine do_simd_last_first_reverse |
| 47 | + |
| 48 | +! Test case 3: Multiple variables with mixed privatization |
| 49 | +! CHECK-LABEL: func.func @_QPdo_simd_multiple_vars |
| 50 | +subroutine do_simd_multiple_vars() |
| 51 | + integer :: a, b, c |
| 52 | + integer :: i |
| 53 | + a = 10 |
| 54 | + b = 20 |
| 55 | + c = 30 |
| 56 | + |
| 57 | + ! CHECK: omp.wsloop |
| 58 | + ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %{{.*}}, @{{.*}}firstprivate{{.*}} %{{.*}} -> %{{.*}} : !fir.ref<i32>, !fir.ref<i32>) |
| 59 | + ! CHECK-NEXT: omp.simd |
| 60 | + !$omp do simd firstprivate(a, b) lastprivate(a) private(c) |
| 61 | + do i = 1, 5 |
| 62 | + a = a + 1 |
| 63 | + b = b + 1 |
| 64 | + c = i |
| 65 | + end do |
| 66 | + !$omp end do simd |
| 67 | +end subroutine do_simd_multiple_vars |
| 68 | + |
| 69 | +! Test case 4: Reproducer from issue #168306 |
| 70 | +! CHECK-LABEL: func.func @_QPissue_168306_reproducer |
| 71 | +subroutine issue_168306_reproducer() |
| 72 | + integer :: a |
| 73 | + integer :: i |
| 74 | + a = 10 |
| 75 | + |
| 76 | + ! CHECK: omp.wsloop |
| 77 | + ! CHECK-SAME: private(@{{.*}}firstprivate{{.*}} %{{.*}} -> %[[FIRSTPRIV_A:.*]] : !fir.ref<i32>) |
| 78 | + ! CHECK-NEXT: omp.simd |
| 79 | + !$omp do simd lastprivate(a) firstprivate(a) |
| 80 | + do i = 1, 1 |
| 81 | + ! Inside the loop, 'a' should start at 10 (from firstprivate) |
| 82 | + ! This is the key behavior that was broken |
| 83 | + a = 20 |
| 84 | + end do |
| 85 | + !$omp end do simd |
| 86 | + ! After the loop, 'a' should be 20 (from lastprivate) |
| 87 | +end subroutine issue_168306_reproducer |
0 commit comments