Background
MLIR has a flexible side-effect mechanism that allows users to track the read and write behavior of each op without explicitly doing so. It can be achieved simply by calling side-effects to query the read and write behavior of ops. However, there is a current drawback to this mechanism: the class EffectInstance, which represents side effects, can only describe the values produced by the side effects, which is not precise enough:
foo.op(%1, %1)
If the side effect of the “foo.op” operation is to read the first operand and write to the second operand, in this scenario, we cannot determine which operands are being read from or written to.
Motivation example
This issue becomes particularly severe when we are optimizing simd memory operations:
copy(A, B) // copy A -> B
add(B, B, C) // first read B and C, then add and write to B
We want to optimize ir above to
add(B, A, C) // first read A and C, then add and write to B
Due to the reasons described in the previous section, we currently lack the means to optimize the program above.
Proposal
My plan is to add a field named operandIndex to the EffectInstance class, with a data type of unsigned, and allow users to query them. This change involves a many of analysis and optimization, so I propose submitting an RFC to gather opinions from everyone.
Any suggestion are welcome.