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

Spencer Bryngelson via flang-commits flang-commits at lists.llvm.org
Thu Jul 23 07:27:39 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());
----------------
sbryngelson wrote:

Done in the latest push. The predicate now walks the RHS def chain and requires it to be rooted in copy-region argument 0. It bails out on reaching argument 1, on any value with no defining op, and on any op carrying regions (those can capture values not in their operand list). Anything not proven original-rooted keeps the normal alias handling.

Added a negative test, `@_QFtestEe_firstprivate`, whose RHS is loaded from the clone: it stays an `hlfir.assign` and is not inlined.

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


More information about the flang-commits mailing list