Not really, you've identified something where the compiler spots a special case pattern and rewrites it, something available to any compiler writer who is sufficiently chummy with the standard library. I'm not saying it isn't useful, but it's nothing like the runtime optimisations the OP was talking about. It can't even handle a for loop...
Closest real world example to a sufficiently smart compiler is GHC, and that can be plenty dumb at times.
Another example is the query planner of a good relational database (PostgreSQL, etc.).
Here, SQL can also be viewed as a lazy evaulated programming language, due to its declarative nature and the fact that the execution order is not defined in the code, but instead an (hopefully optimal) execution order is determined by the query planner.
What was being discussed upthread went a lot further than what you're talking about. The string concat thing is a specific piece of ordinary static analysis that any language with a compile stage can perform. It's also pretty trivially defeated in ways that crop up in real code. I'm not saying it isn't useful, I'm saying it's nowhere close to what would be required to render the performance costs of doing strings the Java way equivalent to the Rust way. Therefore, to go even further upthread, Rust still provides a meaningful choice, trading Java's convenience for Rust's performance.
Closest real world example to a sufficiently smart compiler is GHC, and that can be plenty dumb at times.