Background
tensor.extract_slice
, tensor.insert_slice
and memref.subview
support mixed SSA values/Attributes for offsets, sizes and strides. The idea of this RFC is to extend this “mixed” representation to other ops that index into ranked shaped types.
%0 = tensor.extract_slice %t [%offset, 5] [10, 10] [1, 1] : ...
^ ^
dynamic static
Proposal
- Provide an op interface that has convenience methods for dealing with “mixed values”. Things such as
getMixedOffsets
etc. BasicallyOffsetSizeAndStrideOpInterface
, but without the sizes and strides. Prototype: https://reviews.llvm.org/D156899 - Gradually extend operations that operate on shaped types to support mixed offsets:
tensor.extract
,tensor.insert
,memref.load
,memref.store
,vector.extract
,vector.load
,vector.store
,vector.maskedload
,vector.maskedstore
,vector.transfer_read
,vector.transfer_write
. - Change the signature of
OpBuilder::createOrFold
to returnOpFoldResult
instead ofValue
. (At the moment, it tries to fold the result to an Attribute, and then materializes it as an SSA value with a constant operation.) - Maybe: Use a similar approach to support static/dynamic values for
tensor.dim
,memref.dim
,scf.for
, etc.
Benefits
- More opportunities for op verification: Out-of-bounds access of static indices can be verified. Dynamic indices could be verified in some cases, but such verifiers are discouraged according to the MLIR developer guide (“only verify local aspects of an operation”). Example for
tensor.extract_slice
/tensor.insert_slice
: ⚙ D156061 [mlir][tensor] Improve verifiers: detect out-of-bounds accesses - Better integration with various MLIR helpers that produce or accept
OpFoldResults
. E.g.:affine::makeComposedFoldedAffineApply
, various op builders, … - Fewer operations and IR that is easier to read. In particular, unrolling vector transfer ops generates many
arith.constant
ops (from0
tosize-of-dim
).
I have heard mixed opinions about “mixed values”, so I wanted to discuss this before doubling down on this design principle.