Commit 748e7af
[flang][OpenMP] Fix firstprivate not working with lastprivate in DO SIMD (#170163)
This fixes a bug where firstprivate was ignored when the same variable
had both firstprivate and lastprivate clauses in a do simd construct.
What was broken:
```
integer :: a
a = 10
!$omp do simd firstprivate(a) lastprivate(a)
do i = 1, 1
print *, a ! Should print 10, but printed garbage/0
a = 20
end do
!$omp end do simd
print *, a ! Correctly prints 20
```
Inside the loop, [a] wasn't being initialized from the firstprivate
clause—it just had whatever uninitialized value was there.
The fix:
In genCompositeDoSimd(), we were using simdItemDSP to handle
privatization for the whole loop nest. This only looked at SIMD clauses
and missed the firstprivate from the DO part. Changed it to use
wsloopItemDSP instead, which handles both DO clauses (firstprivate,
lastprivate) correctly.
One line change in OpenMP.cpp
Tests added:
Lowering test to check MLIR generation
Runtime test to verify the actual values are correct
<img width="740" height="440" alt="image"
src="https://github.com/user-attachments/assets/fa911ea8-2024-4edf-b710-52c10659742e"
/>
Fixes #168306
---------
Co-authored-by: Krish Gupta <[email protected]>1 parent db59def commit 748e7af
File tree
5 files changed
+151
-23
lines changed- flang
- lib/Lower/OpenMP
- test
- Integration/OpenMP
- Lower/OpenMP
5 files changed
+151
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3314 | 3314 | | |
3315 | 3315 | | |
3316 | 3316 | | |
3317 | | - | |
3318 | | - | |
3319 | | - | |
3320 | | - | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
3321 | 3321 | | |
3322 | 3322 | | |
3323 | | - | |
3324 | | - | |
3325 | | - | |
3326 | | - | |
3327 | | - | |
3328 | 3323 | | |
3329 | 3324 | | |
3330 | 3325 | | |
| |||
3343 | 3338 | | |
3344 | 3339 | | |
3345 | 3340 | | |
3346 | | - | |
3347 | | - | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
3348 | 3344 | | |
3349 | 3345 | | |
3350 | 3346 | | |
| |||
3354 | 3350 | | |
3355 | 3351 | | |
3356 | 3352 | | |
3357 | | - | |
| 3353 | + | |
3358 | 3354 | | |
3359 | 3355 | | |
3360 | 3356 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
Lines changed: 89 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | | - | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | 79 | | |
81 | 80 | | |
82 | | - | |
83 | | - | |
84 | 81 | | |
85 | 82 | | |
86 | 83 | | |
| |||
90 | 87 | | |
91 | 88 | | |
92 | 89 | | |
93 | | - | |
| 90 | + | |
94 | 91 | | |
95 | | - | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
100 | 95 | | |
101 | 96 | | |
102 | 97 | | |
| |||
0 commit comments