Enable constant propagation across Switch(x,x) by rewriting the two outputs as Const(false), Const(true) with appropriate control dependencies. This is a fairly common pattern when the graph contains assertions.
By rewriting the graph a bit, we can propagate the constants down the two output branches, and just use control dependencies to trigger the selected one at runtime. For example,
+------+
x-->|Switch|-->a
x-->| |-->b
+------+
Is rewritten as
+------+
x-->|Switch|-->Identity--^>Const(false)-->a
x-->| |-->Identity--^>Const(true)-->b
+------+
(In practice there may be multiple consumers of each output branch.)
PiperOrigin-RevId:
186714991