Fix crash du to opt that introduce cycle in the graph

NEWS.txt
Fix crash caused by an optimization that introduce cycle in the graph (Frederic Bastien, reported by Axel Davy)
If I understand correctly this will check that for a replacement that is not equivalent to the source node (as in computes the same operation with the same inputs) and reject such a change.

Do you have a test case where this happens?