[all-commits] [llvm/llvm-project] 0572ad: [mlir][shape] Fix crash when folding tensor.extrac...

Mehdi Amini via All-commits all-commits at lists.llvm.org
Fri Mar 13 06:17:30 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0572ad60f354f86deddf4bd364fd0145d7a146ea
      https://github.com/llvm/llvm-project/commit/0572ad60f354f86deddf4bd364fd0145d7a146ea
  Author: Mehdi Amini <joker.eph at gmail.com>
  Date:   2026-03-13 (Fri, 13 Mar 2026)

  Changed paths:
    M mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
    M mlir/test/Dialect/Shape/canonicalize.mlir

  Log Message:
  -----------
  [mlir][shape] Fix crash when folding tensor.extract(shape_of(memref)) (#186270)

The `ExtractFromShapeOfExtentTensor` canonicalization pattern was
unconditionally rewriting:

  tensor.extract(shape.shape_of(%arg), %idx) -> tensor.dim(%arg, %idx)

even when `%arg` is a memref. This produced an invalid `tensor.dim`
(whose source operand must be a tensor), which then caused an assertion
failure in `DimOp::getSource()` when subsequent canonicalization
patterns tried to match the op:

Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type\!"'
  failed.  [To = TypedValue<TensorType>, From = Value]

Fix: add an `IsTensorType` constraint to
`ExtractFromShapeOfExtentTensor` in `ShapeCanonicalization.td` so the
pattern only fires when `%arg` is a tensor type. The memref case is
intentionally left unfolded (the correct lowering to `memref.dim` would
require adding a MemRef dependency to the Shape dialect, which is not
desirable).

Tests cover both the positive case (tensor arg folds to tensor.dim) and
the negative case (memref arg is left unmodified).

Fixes #185248

Assisted-by: Claude Code



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