[flang-commits] [flang] [flang][OpenMP] Inline the firstprivate array copy instead of calling Assign() (PR #211543)

Sairudra More via flang-commits flang-commits at lists.llvm.org
Thu Jul 23 08:01:47 PDT 2026


================
@@ -39,6 +40,22 @@ static llvm::cl::opt<bool> inlineAllocatableExprAssignFlag(
                    "hlfir.expr (e.g., from hlfir.elemental)"),
     llvm::cl::init(false));
 
+/// Is \p assign the copy-in of an `omp.private` copy region, writing the
+/// privatized clone? The operation defines its first copy-region block
+/// argument to be the original host variable and the second to be the memory
+/// allocated for the clone, so the two cannot overlap and the copy can be
+/// inlined without an aliasing check.
+static bool isOmpPrivateCopyInAssign(hlfir::AssignOp assign) {
+  mlir::Region *region = assign->getParentRegion();
+  auto privateOp =
+      llvm::dyn_cast_or_null<mlir::omp::PrivateClauseOp>(region->getParentOp());
+  if (!privateOp || region != &privateOp.getCopyRegion())
+    return false;
+  auto blockArg = llvm::dyn_cast<mlir::BlockArgument>(assign.getLhs());
----------------
Saieiei wrote:

Thanks, The direct clone-rooted case is covered, but this still looks too permissive. `isRootedInOriginalArg()` treats every regionless op as provenance-preserving; for example, a `fir.call` can take `%arg0` yet return unrelated memory through hidden/global state. The LHS check also accepts argument 1 of any block, not specifically the entry clone argument. Since `omp.private` permits unrestricted multi-block bodies, verifier-valid overlapping cases can still bypass the temporary path. Could this require the entry clone argument and restrict the RHS to known provenance-preserving or canonical operations, with targeted negative coverage?

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


More information about the flang-commits mailing list