This is an archive of the discontinued LLVM Phabricator instance.

[mlir][MemRef|Tensor] Fix the handling of DimOp
ClosedPublic

Authored by qcolombet on Feb 14 2023, 3:37 AM.

Details

Summary

Although specifying an index that is out of bounds for both memref.dim
and tensor.dim produces an undefined behavior, this is still valid IR.
In particular, we could expose an out of bound index because of some
optimizations, for instance as demonstrated with
https://github.com/llvm/llvm-project/issues/60295, and this shouldn't
cause the compiler to abort.

This patch removes the overzealous verifier checks and properly handles
out of bound indices (as in it doesn't crash the compiler, but still
produces UB).

This fixes https://github.com/llvm/llvm-project/issues/60295.

Note: That shape.dim has a similar problem but we're not supposed to
produce UB in this case. Instead we're supposed to propagate an error in
the resulting value and I don't know how to do that at the moment. Hence I
left this part out of the patch.

Diff Detail

Event Timeline

qcolombet created this revision.Feb 14 2023, 3:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2023, 3:37 AM
qcolombet requested review of this revision.Feb 14 2023, 3:37 AM
mehdi_amini accepted this revision.Feb 14 2023, 10:01 AM
This revision is now accepted and ready to land.Feb 14 2023, 10:01 AM
This revision was automatically updated to reflect the committed changes.