compiler-optimization


Why does the enhanced GCC 6 optimizer break practical C++ code?

I guess the question that needs to be answered why well-intentioned people would write the checks in the first place. The most common case is probably if you have a class that is part of a naturally... Read More


c - How do I make an infinite empty loop that won't be optimized away?

The C11 standard says this, 6.8.5/6: An iteration statement whose controlling expression is not a constant expression,156) that performs no input/output operations, does not access volatile objects,... Read More


c++ - Is there a reason why not to use link-time optimization (LTO)?

I assume that by "production software" you mean software that you ship to the customers / goes into production. The answers at Why not always use compiler optimization? (kindly pointed out by Mankars... Read More


c++ - Why does using the ternary operator to return a string generate considerably different code from returning in an equivalent if/else block?

The overarching difference here is that the first version is branchless. 16 isn’t the length of any string here (the longer one, with NUL, is only 15 bytes long); it’s an offset into the return objec... Read More


c++ - Why are elementwise additions much faster in separate loops than in a combined loop?

Upon further analysis of this, I believe this is (at least partially) caused by the data alignment of the four-pointers. This will cause some level of cache bank/way conflicts. If I've guessed correc... Read More


c++ - Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviations with _mm_popcnt_u64 on Intel CPUs

Culprit: False Data Dependency (and the compiler isn't even aware of it) On Sandy/Ivy Bridge and Haswell processors, the instruction: popcnt src, dest appears to have a false dependency on the dest... Read More


c++ - Why doesn't 'd /= d' throw a division by zero exception when d == 0?

C++ does not have a "Division by Zero" Exception to catch. The behavior you're observing is the result of Compiler optimizations: The compiler assumes Undefined Behavior doesn't happen Division by Z... Read More


c++ - Why do we use volatile keyword?

Consider this code, int some_int = 100; while(some_int == 100) { //your code } When this program gets compiled, the compiler may optimize this code, if it finds that the program never ever makes... Read More


c++ - What is &&& operation in C

It's c = i && (&i);, with the second part being redundant, since &i will never evaluate to false. For a user-defined type, where you can actually overload unary operator &, it might be different, but... Read More


Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

Rust originally did enable LLVM's noalias attribute, but this caused miscompiled code. When all supported LLVM versions no longer miscompile the code, it will be re-enabled. If you add -Zmutable-noal... Read More