Improve optimizer

Most of the size improvements comes from the first commit. But a bit of it also comes from the second commit.
`finishTransformStat` does that (better, since it avoids forcing `texpr` if unnecessary).