[mlir][tensor|memref] Harden the checks on dim op
authorQuentin Colombet <quentin.colombet@gmail.com>
Tue, 24 Jan 2023 10:29:37 +0000 (11:29 +0100)
committerQuentin Colombet <quentin.colombet@gmail.com>
Thu, 2 Feb 2023 10:34:03 +0000 (11:34 +0100)
commit3810f76c50923dd0ef16ace6a550e5a4ab6c16a5
treeae40c2e45e5687fefff0fda016ac61dd72dcd68a
parente67f1480232ee389d0988d10d733bf45c5665a11
[mlir][tensor|memref] Harden the checks on dim op

Prior to this patch it was possible to use the dim operation on a 0-D
memref/tensor.
Unless we want to change the semantic of a 0-D shape, this doesn't make
sense because, paraphrasing the dim op semantic, this is guaranteed to
produce something that is undefined. (The requested index is guaranteed
to be equal to or greater than the rank.)

Harden the type requirements for the dim op by disallowing 0-D shaped
types.

This "fixes" llvm.org/PR60195 by rejecting dim op on 0-D shapes instead of
crashing during LLVM conversion.

Differential Revision: https://reviews.llvm.org/D142445
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
mlir/include/mlir/IR/OpBase.td
mlir/test/Dialect/MemRef/invalid.mlir
mlir/test/Dialect/Tensor/bufferize.mlir
mlir/test/Dialect/Tensor/invalid.mlir