This is an archive of the discontinued LLVM Phabricator instance.

Correctly model undefined behavior in {tensor|memref}.dim
ClosedPublic

Authored by sanjoy on Oct 11 2022, 10:55 PM.

Details

Summary

These operations have undefined behavior if the index is not less than the rank of the source tensor / memref, so they cannot be freely speculated like they were before this patch. After this patch we speculate them only if we can prove that they don't have UB.

Depends on D135505.

Diff Detail

Event Timeline

sanjoy created this revision.Oct 11 2022, 10:55 PM
sanjoy requested review of this revision.Oct 11 2022, 10:55 PM
jpienaar added inline comments.
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
827

If you used ShapedType and hasRank then you'd be able to use same implementation for both ops.

sanjoy added inline comments.Oct 12 2022, 8:42 AM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
827

Specifically, are you suggesting I create a include/mlir/Dialect/Utils/DimOpUtils.h and put the shared implementation there?

rriddle added inline comments.Oct 12 2022, 3:35 PM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
827

I'd rather just duplicate the implementations than add more to Dialect/Utils.

833–834

Do you really need the (void) on these? The variables aren't unused AFAICT.

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
342

Same here.

mlir/test/Transforms/loop-invariant-code-motion.mlir
512

Please indent the checks with the IR.

mravishankar accepted this revision.Oct 12 2022, 3:44 PM

Thanks Sanjoy! This makes sense to me.

This revision is now accepted and ready to land.Oct 12 2022, 3:44 PM
sanjoy updated this revision to Diff 467312.Oct 12 2022, 5:25 PM
sanjoy marked 2 inline comments as done.

Address review

This revision was landed with ongoing or failed builds.Oct 12 2022, 5:30 PM
This revision was automatically updated to reflect the committed changes.