[flang-commits] [flang] [Flang]Add support for inlining hlfir.assign operation where both LHS and RHS are slices of the same array (PR #204532)
Kaviya Rajendiran via flang-commits
flang-commits at lists.llvm.org
Tue Jun 23 09:24:38 PDT 2026
================
@@ -130,6 +136,43 @@ class InlineHLFIRAssignConversion
fir::FirOpBuilder builder(rewriter, assign.getOperation());
builder.setInsertionPoint(assign);
+ const bool useWorkshare = flangomp::shouldUseWorkshareLowering(assign);
+ mlir::ArrayAttr accessGroups;
+ if (auto attrs = assign.getOperation()->getAttrOfType<mlir::ArrayAttr>(
+ fir::getAccessGroupsAttrName()))
+ accessGroups = attrs;
+
+ auto emitAssignFrom = [&](hlfir::Entity rhsEntity) {
+ hlfir::genNoAliasArrayAssignment(
+ loc, builder, rhsEntity, lhs, useWorkshare,
+ /*temporaryLHS=*/false, nullptr, accessGroups);
+ };
+
+ if (rhsNeedsTemporary) {
+ if (mlir::Value disjoint =
+ fir::ArraySectionAnalyzer::genRuntimeDisjointnessCheck(
+ loc, builder, lhs, rhs)) {
+ builder.genIfThenElse(loc, disjoint)
+ .genThen([&]() { emitAssignFrom(rhs); })
+ .genElse([&]() {
+ mlir::Value tempExpr = hlfir::AsExprOp::create(builder, loc, rhs);
+ emitAssignFrom(hlfir::Entity{tempExpr});
+ hlfir::DestroyOp::create(builder, loc, tempExpr);
+ })
+ .end();
+ rewriter.eraseOp(assign);
+ return mlir::success();
+ }
+ }
+
+ // When rhsNeedsTemporary is true and genRuntimeDisjointnessCheck
+ // returned null, always use a temporary rhsExpr.
+ mlir::Value rhsTempExpr;
+ if (rhsNeedsTemporary) {
+ rhsTempExpr = hlfir::AsExprOp::create(builder, loc, rhs);
+ rhs = hlfir::Entity{rhsTempExpr};
+ }
----------------
kaviya2510 wrote:
As you mentioned, this fallback check is not required for current implementation. So removed it.
https://github.com/llvm/llvm-project/pull/204532
More information about the flang-commits
mailing list