4 ms·
> It's basically impossible to optimize induction variables without undefined signed overflow Here's a piece of code you can compile with: gcc -O3 -Wall -
by xscott 4y ago
> It's basically impossible to optimize induction variables without undefined signed overflow
Here's a piece of code you can compile with:
gcc -O3 -Wall -Wextra mandel.c -DINTEGER=size_t -o mansize
gcc -O3 -Wall -Wextra mandel.c -DINTEGER=int -o manint
https://godbolt.org/z/Wx4aavvjj https://godbolt.org/z/Wx4aavvjj
Both versions, the one with the signed integer UB you claim is so important, and the one using size_t with no UB worries at all run in about .28 seconds on my desktop.
I can imagine you'll have some objection: This isn't a true Scotsman, or this isn't representative of real world code, or this example makes it too easy for the compiler to optimize, or that's not about induction variables, or something creative...
That's fine, but the next example is on you. I look forward to seeing what you come up with.
> it's possibly the most important optimization for C code, maybe after inlining and simple manipulations such as dead code elimination.
Dead code elimination is one of the most important optimizations?!? Are you worried about binary size or CPU time?
- bonzini 4y ago> This isn't a true Scotsman, or this isn't representative of real world code It is, but induction variables optimization generally requires lots of memory accesses. I will try to come up with something. > Dead code elimination is one of the most important optimizations Yes, inlined code has a lot of constant conditions and code that similarly only follows one path only. Dead code elimination, constant propagation, eliminating stuff like &*x so that x can stay in a register, are all very important to achieve zero-cost abstraction. Mostly in C++, Rust and the like, but also in C.