Pattern matching on function application
If you are given that $g(f(x))=x$ for all $x$ and $f,g$ are pure functions, then your proposed transformation works.  However, the condition $f(g(x))=x$ is not sufficient: consider $f,g:\mathbb{N} \to \mathbb{N}$ given by $g(x)=2x$, $f(x)=\lfloor x/2 \rfloor$.  (I'm not sure which your g . f notation was intended to capture.)