[mlir] Tighten the rules around folding TensorLoadOp

Authored by nicolasvasilache on Mar 4 2021, 9:36 AM.


[mlir] Tighten the rules around folding TensorLoadOp

tensor_load(tensor_to_memref(x)) -> x is an incorrect folding because it ignores potential aliasing.

This revision approximates no-aliasing by restricting the folding to occur only when tensor_to_memref
is immediately preceded by tensor_load in the same block. This is a conservative step back towards
correctness until better alias analysis becomes available.

Context: https://llvm.discourse.group/t/properly-using-bufferization-related-passes/2913/6

Differential Revision: https://reviews.llvm.org/D97957