3 ms·
Very interesting. In the same vein, I once stumbled upon the following optimizer behaviour: ''' int array[8]; // later array[i] ''' The optimizer deduces from
by Ace17 10y ago
Very interesting.
In the same vein, I once stumbled upon the following optimizer behaviour:
'''
int array[8];
// later
array[i]
'''
The optimizer deduces from the access "array[i]" that "i >= 0 && i < 8".
(leading it to optimizing away conditions like "i > 10").
Of course, if optimization leads to semantic differences, this means the program being compiled was wrong/ambiguous in the first place. However, now, to debug your programs, you must know how optimizers work.
- krylon 10y agoA couple of years back, I worked at a company where I helped maintaining a Win32 application written in C, using (Open)Watcom as the compiler. A few years before I started working there, the other programmers had been bitten by a bug in Watcom's optimizer that sometimes would wrongly optimize away comparisons involving floating point numbers. Consequently, all code was compiled with optimizations disabled completely. (I tried to debate, but then I compiled the project with most optimizations enabled and did a benchmark - the difference in performance was minimal, so I stopped bothering).