[flang-commits] [flang] [llvm] [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 07:15:58 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:

Could this also verify that the RHS is derived from copy-region argument 0 before skipping the alias checks? The copy-region body is unrestricted, while this predicate only checks that the LHS is argument 1. A clone-rooted overlapping RHS would therefore bypass the temporary/disjointness handling and be lowered using the no-alias element loop. Could we retain alias handling unless the RHS is proven to originate from the original variable?

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


More information about the flang-commits mailing list