• Hi, I’ve been investigating the -promote-to-affine pass in flang (AffinePromotion.cpp) and its interaction with downstream MLIR affine loop optimization (specifically -affine-loop-tile). • The current pass linearizes multi-dimensional Fotran array accesses into 1D memref accesses, which cause MLIR’s polyhedral dependence analysis to produce false dependence, preventing loop tiling on perfectly tileable loops. • consider simple fotran program": ```fortran program test integer :: A(100,100), B(100,100), C(100,100) do i = 1, 100 do j = 1, 100 A(i,j) = B(i,j) + C(i,j) end do end do end program After lowering to FIR (with itr_args simplified away), the inner loop body uses fir.array_coor with two separate indices preserving the 2D nature. • %31 = fir.array_coor %B(%shape) %arg0, %arg2: (!fir.ref>, ! • fir.shape<2>, index, index) → !fir.ref %32 = fir.load %31: !fir.ref After applying -promote-to-affine, the pass linearizes the 2D array accesses into single 1D access: #map1 = affine_map<(d0, d1)[s0, s1, s2, s3, s4, s5] → ((d1 * s5 - s3) * s1 + d0 * s2 - s0)> %16 = affine.apply #map1(%arg0, %arg1)[%c1, %c100, %c1, %c1, %c100, %c1] %17 = fir.convert %B : (!fir.ref >) -> memref %18 = affine.load %17[%16] : memref Approach 1: Post-promotion delinearization pass Keep the current -promote-to-affine linearization as -is , but add a new pass that run after promotion and delinearizes the 1D memref access back to multi-dimensional memref<100x100xi32> accesses. • After loop tiling (or other affine o
Article Summaries:
- A recent discussion highlights a limitation in Flang’s -promote-to-affine pass: it linearizes multi‑dimensional Fortran array accesses into 1‑D memref accesses, causing MLIR’s polyhedral dependence analysis to register false dependencies and preventing loop‑tiling on otherwise tileable loops. The author demonstrates the problem with a simple 100×100 array copy and proposes three remedies: (1) add a post‑promotion delinearization pass and a pre‑lowering re‑linearization, (2) introduce an intermediate representation that preserves Fortran array semantics while remaining analyzable, and (3) modify the promotion to emit multi‑dimensional memref indices directly. The post asks whether similar work is underway and which approach best fits the project’s direction.
Sources: