[RFC] Prevent CSE from removing expressions inside some non-`IsolatedFromAbove` operation regions

You stated it above. My idea is that my IR must be valid and cope with optimizations passes without getting into invalid state. My IR must cope with CSE, constant propagation, code motion, and future optimizations. The ÌsolatedFromAbove interface already exists and I believe that the target region must be protected by the existing interface.

The above mentioned hoisting of v1[0] is an invalid transformation.

I agree if ‘OperationEquivalence’ can be overridden by enclosing ops, meaning op.region should be able to say that two ops are not equivalent because it has changed the state somehow. On a CPU this could be modifying a control register e.g. rounding mode.

I think what we will do in the case of omp.target and similar ops is to make them IsolatedFromAbove if we find that optimizations cause problem. This seems to be the most practical approach given what MLIR is doing today. It will not have any negative effects with respect to optimizations since none are allowed anyway for omp.target at least.

2 Likes