Certainly easy enough to experiment...
https://godbolt.org/z/xcaPnq5YW
I get the same results on this independent of ISA or gcc/clang.
Ahh, interesting that it simplifies 2, but not 3...
Ah, that makes sense, -funsafe-math-optimizations will generate the [naively] expected code (but it might not distribute errors exactly the way you like, hence the name of the option). I suppose squaring being a binary operation (x * x), order doesn't matter, but for other powers it does. Also works for negative powers (emitting a division op, and whatever muls to get it there).
Yeah. Of course, there is no hard rule about this at all and so it's 100% compiler-dependent. I would also expect it to support only a restricted range of functions and possible values.
I guess only if you use C++ "constexpr" can you be sure enough that what can be computed at compile-time will be and give the same result as it would during run time.