Insert casts when specializing function arguments to avoid illegal IR.
Insert casts when specializing function arguments to avoid illegal IR.

The latter can happen if the consumer of the operand does not support changes to operand types. Examples are std.return or control flow operations that need further fixups on operand changes.

Also fix an issue in tf shape inference where it would not propagate shape knowledge through tensor.cast.

PiperOrigin-RevId: 423059539

tensorflow/runtime,tensorflow/runtime,tensorflow/runtime,tensorflow/runtime