This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector][NFC] Allow out-of-bounds starting positition for vector transfer ops
ClosedPublic

Authored by springerm on Jul 19 2023, 8:59 AM.

Details

Summary

The starting indices of all vector dimensions are allowed to be out-of-bounds.

E.g.:

// %j is allowed to be out-of-bounds (but not %i).
%0 = vector.transfer_read %m[%i, %j] ... {in_bounds = [false]} : memref<?x?xf32>, vector<5xf32>

This revision just updates the op documentation and adds extra test cases. Out-of-bounds starting points are already supported by the respective lowerings:

  • 2D and higher-dimensional transfers are lowered to 1D transfers by VectorToScf. These patterns generate an scf.if check for every (potentially unrolled) loop iteration if the dimension is in_bounds = false, including the first loop iteration.
  • 1D out-of-bounds transfers are lowered to in-bounds transfers by MaterializeTransferMask, which adds a mask to the op. The mask is defined by vector.create_mask (dim-size) - (index). In case of an out-of-bounds starting point, the operand of the vector.create_mask op is 0 or negative. Negative operands are treated like 0 according to the documentation of vector.create_mask.

Diff Detail

Event Timeline

springerm created this revision.Jul 19 2023, 8:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
springerm requested review of this revision.Jul 19 2023, 8:59 AM
Herald added a project: Restricted Project. · View Herald Transcript

Use case for this revision: A tensor.pad vectorizes into a vector.transfer_read/vector.transfer_write pair. A tiled tensor.pad may have an empty source (i.e., result consists of only padding). When vectorizing such a tensor.pad, we get a vector.transfer_read with an out-of-bounds starting index.

springerm retitled this revision from [mlir][vector] Allow out-of-bounds starting positition for vector transfer ops to [mlir][vector][NFC] Allow out-of-bounds starting positition for vector transfer ops.Jul 19 2023, 9:02 AM
aartbik accepted this revision.Aug 1 2023, 1:12 PM
This revision is now accepted and ready to land.Aug 1 2023, 1:12 PM