[flang-commits] [flang] [flang][OpenMP] Fix firstprivate not working with lastprivate in DO SIMD (PR #170163)
Krish Gupta via flang-commits
flang-commits at lists.llvm.org
Mon Dec 1 11:17:51 PST 2025
KrxGu wrote:
> I'm not sure about your interpretation of the spec. There is no firstprivate clause for the simd construct so the firstprivate cannot apply to the simd. Running flang without your patch it looks like we correctly apply firstprivate and lastprivate to the wsloop but only lastprivate to simd.
>
> This results in LLVM codegen where there are three private variables: the firstprivate copy of a for `omp do` - this is unused and would be removed by the optimizer; the private copy of `a` used in the body of `omp simd`; and the private copy of the loop iteration variable. As you observed, this means that the value of `a` inside the loop is uninitialized memory.
>
> If this is a bug then I think the bug is that there are two completely separate declarations and memory for `a`. This is still visible in your lit test.
Thanks - that makes sense. I agree firstprivate isn’t a clause on simd, so the goal shouldn’t be to “apply firstprivate to simd”. The real issue is that our lowering materializes two independent private storages for a (firstprivate on wsloop and lastprivate/private on simd), and the loop body ends up using the simd one (uninitialized). I’ll rework the patch so omp.simd reuses the wsloop privatization for list items already privatized by wsloop (i.e. no second omp.private/alloca for a) and adjust the lit test accordingly. Does that match the intended approach?
https://github.com/llvm/llvm-project/pull/170163
More information about the flang-commits
mailing list