[all-commits] [llvm/llvm-project] 068646: [FIRToMemRef] Fix wrong indexing for converted arr...

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Tue Jul 7 03:53:50 PDT 2026


  Branch: refs/heads/users/ergway/firtomemref-emboxed-slice-offset
  Home:   https://github.com/llvm/llvm-project
  Commit: 068646c2a1771803d6ba051e06b7d4ec84b8b94c
      https://github.com/llvm/llvm-project/commit/068646c2a1771803d6ba051e06b7d4ec84b8b94c
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-06 (Mon, 06 Jul 2026)

  Changed paths:
    M flang/lib/Optimizer/Transforms/FIRToMemRef.cpp
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-array-coor.mlir
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-rank-reduction.mlir
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-stride.mlir

  Log Message:
  -----------
  [FIRToMemRef] Fix wrong indexing for converted array_coor over sliced fir.embox

FIRToMemRef::convertArrayCoorOp routes through getMemrefIndices, which
only folds the first `rank` triples of sliceInfo.sliceVec into the memref
indices (i.e. the array_coor's own slice); the embox's slice triples --
which sit at [rank*3 .. 2*rank*3-1] when both are present -- were dropped.
Three consequences, three fixes here:

  1. Non-collapsed embox slice lbs contribute (lb - 1) per Fortran dim to
     each memref index. Fold them in in memref order (reversed Fortran
     order) so the reinterpret_cast view lands at the right column.

  2. The shapeVec-else stride path used shapeVec[0..rank-1] to build the
     outer strides. With both slices present, that's the box's (slice's)
     extents. Use shapeVec[rank..2*rank-1] instead -- the parent's extents
     -- so the outer stride is the parent's leading dim rather than the
     slice's own size.

  3. Rank-reducing embox slices (undef ub/step triples) have no memref
     index position for their (lb - 1) shift. Fold the collapsed dim's
     (lb - 1) * parent_stride into the reinterpret_cast's flat offset and
     override the corresponding memref index entry to 0.

Co-Authored-By: Claude Opus 4.7 <noreply at anthropic.com>


  Commit: 03dafe26d181cbacd18df615605cb9f194a557d8
      https://github.com/llvm/llvm-project/commit/03dafe26d181cbacd18df615605cb9f194a557d8
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-07 (Tue, 07 Jul 2026)

  Changed paths:
    M flang/lib/Optimizer/Transforms/FIRToMemRef.cpp
    M flang/test/Transforms/FIRToMemRef/emboxed-slice-array-coor.mlir
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-non-unit-stride-non-unit-lb.mlir
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-rank-reduction-nonprefix.mlir
    M flang/test/Transforms/FIRToMemRef/emboxed-slice-rank-reduction.mlir
    M flang/test/Transforms/FIRToMemRef/emboxed-slice-stride.mlir

  Log Message:
  -----------
  Review comments: non-unit stride


Compare: https://github.com/llvm/llvm-project/compare/10c05fed6fb4...03dafe26d181

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list