[flang-commits] [flang] [flang][OpenMP] Fix wrong results for FORALL in a workshare construct (PR #211371)

Carlos Seo via flang-commits flang-commits at lists.llvm.org
Fri Jul 24 08:50:10 PDT 2026


================
@@ -485,7 +545,10 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
           delete singleBlock;
         } else {
           omp::SingleOperands singleOperands;
-          if (isLast)
+          // nowait and copyprivate are mutually exclusive on a single
+          // construct: the broadcast relies on the barrier at the end of the
+          // region.
+          if (isLast && copyprivateVars.empty())
----------------
ceseo wrote:

`write_then_read` is a `single` that `isLast`, but it carries a `copyprivate(%0)`:

```
$ ./build/bin/fir-opt --lower-workshare --allow-unregistered-dialect --split-input-file /tmp/wo.mlir 2>&1 | sed -n '/func.func @write_then_read/,/^  }$/p'

  func.func @write_then_read(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>) {
    omp.parallel {
      %0 = fir.alloca i32
      omp.single copyprivate(%0 -> @_workshare_copy_i32 : !fir.ref<i32>) {
        %2 = fir.load %arg0 : !fir.ref<i32>
        fir.store %2 to %0 : !fir.ref<i32>
        omp.terminator
      }
      omp.barrier
      %1 = fir.load %0 : !fir.ref<i32>
      fir.store %1 to %arg1 : !fir.ref<i32>
      omp.terminator
    }
    return
  }
 ```

https://github.com/llvm/llvm-project/pull/211371


More information about the flang-commits mailing list