[OpenMP] Fix the issue where `num_threads` still takes effect incorrectly
authorShilei Tian <i@tianshilei.me>
Wed, 14 Jun 2023 15:45:49 +0000 (11:45 -0400)
committerShilei Tian <i@tianshilei.me>
Wed, 14 Jun 2023 15:46:12 +0000 (11:46 -0400)
commit85592d3d4d402b99df32bcc711bca56a8a593c97
tree3700eba12361be6971ceea9ba7b9fce8ffa20262
parent27fac4a72ae54a471471a69c0ad999585ccbb026
[OpenMP] Fix the issue where `num_threads` still takes effect incorrectly

This patch fixes the issue that, if we have a compile-time serialized parallel
region (such as `if (0)`) with `num_threads`, followed by a regular parallel
region, the regular parallel region will pick up the value set in the serialized
parallel region incorrectly. The reason is, in the front end, if we can prove a
parallel region has to serialized, instead of emitting `__kmpc_fork_call`, the
front end directly emits `__kmpc_serialized_parallel`, body, and `__kmpc_end_serialized_parallel`.
However, this "optimization" doesn't consider the case where `num_threads` is
used such that `__kmpc_push_num_threads` is still emitted. Since we don't reset
the value in `__kmpc_serialized_parallel`, it will affect the next parallel region
followed by it.

Fix #63197.

Reviewed By: tlwilmar

Differential Revision: https://reviews.llvm.org/D152883
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/test/parallel/bug63197.c [new file with mode: 0644]