ketmar wrote:i *definitely* know better, that's why compilers still cannot write code for me. if i wrote some check, i want it to be there, regardless of what compiler believes. if i am left-shifting into sign bit, i know what i am doing. and so on.
So we should always compile with -O0? All optimizations are tossing some of your code out. Or writing code for you in the case of things like inlining which you know could break any undefined back-patching you do to your functions.
ketmar wrote:is there any way to left-shift into sign bit w/o UB, for example?
My cop out answer: use C++20
ketmar wrote:and using union is in no way better, because the code is still assuming two-complement math.
More specifically using a union in that way is undefined behavior regardless of what you're doing with it. The standard says you can only read from the member you last assigned to. IIRC C is slightly relaxed in this regard, but most union tricks like this are just a way of doing undefined behavior in a way the compiler can't warn about even in C.
ketmar wrote:i don't care if compiler can "deduce" that my null check is not required, because "dereferencing null pointer cannot happen, ever." if i wrote that check, i want it to be there, and i know better.
I on the other hand would like it to deduce these things so when it inlines code it can remove branches that may only be needed in some cases.
dpJudas wrote:Vector optimizations is a bad example for this.
While I may agree that your examples are better in regards to most applicable speed ups, the main reason I cited vector optimizations is they're the primary reason for "new GCC broke my code" in my experience. And the reason is almost always type casting breaking data alignment guarantees for a given type.