[flang-commits] [flang] [Flang]Add support for inlining hlfir.assign operation where both LHS and RHS are slices of the same array (PR #204532)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Wed Jun 24 08:20:26 PDT 2026


================
@@ -193,6 +194,56 @@ ArraySectionAnalyzer::analyze(mlir::Value ref1, mlir::Value ref2,
   return SlicesOverlapKind::Unknown;
 }
 
+mlir::Value ArraySectionAnalyzer::genRuntimeDisjointnessCheck(
+    mlir::Location loc, mlir::OpBuilder &builder, mlir::Value lhsRef,
+    mlir::Value rhsRef) {
+  auto des1 = lhsRef.getDefiningOp<hlfir::DesignateOp>();
+  auto des2 = rhsRef.getDefiningOp<hlfir::DesignateOp>();
+  if (!des1 || !des2)
+    return {};
+
+  if (des1.getMemref() != des2.getMemref())
+    return {};
+
+  if (des1.getComponent() != des2.getComponent() ||
+      des1.getComponentShape() != des2.getComponentShape() ||
+      des1.getSubstring() != des2.getSubstring() ||
+      des1.getComplexPart() != des2.getComplexPart() ||
+      des1.getTypeparams() != des2.getTypeparams())
+    return {};
+
+  if (des1.getIsTriplet().empty() ||
+      !llvm::equal(des1.getIsTriplet(), des2.getIsTriplet()))
+    return {};
+
+  mlir::Type idxTy = mlir::IndexType::get(des1.getContext());
+  auto toIdx = [&](mlir::Value v) -> mlir::Value {
+    return fir::ConvertOp::create(builder, loc, idxTy, v);
+  };
+
+  mlir::Value disjoint;
+  auto des1It = des1.getIndices().begin();
+  auto des2It = des2.getIndices().begin();
+  for (bool isTriplet : des1.getIsTriplet()) {
+    SectionDesc desc1 = readSectionDesc(des1It, isTriplet);
+    SectionDesc desc2 = readSectionDesc(des2It, isTriplet);
+    auto [lb1, ub1] = getOrderedBounds(desc1);
----------------
vzakhari wrote:

Thank you for checking! I forgot about the normalization.

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


More information about the flang-commits mailing list