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

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Thu Jul 9 00:55:43 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e795686d2eb7fbee7e594451b46687a3c8d1f575
      https://github.com/llvm/llvm-project/commit/e795686d2eb7fbee7e594451b46687a3c8d1f575
  Author: Kareem Ergawy <kergawy at nvidia.com>
  Date:   2026-07-09 (Thu, 09 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-non-unit-stride-non-unit-lb.mlir
    A flang/test/Transforms/FIRToMemRef/emboxed-slice-rank-reduction-nonprefix.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 (#207749)

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>



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