Unexpected optimization of strlen when aliasing 2-d array

I checked this and it reproduced with -O1 on gcc 8.3, so I just opened list of gcc optimization flags here and started experimenting with them one by one. It turned out that disabling only sparse conditional constant propagation with -fno-tree-ccp made the problem disappear (oh luck, I planned to test couples of flags if … Read more

Visual Studio 2015 Update 3 – C++ Compiler bug?

Yes, it’s a bug. Specifically, it’s a bug in the new SSA optimizer introduced in VS2015 Update 3. The undocumented command line option -d2SSAOptimizer- tells the compiler backend to use the old optimizer instead, which causes the bug to not manifest. FYI, you can minimize your repro to: int main() { volatile int someVar = … Read more

How to guide GCC optimizations based on assertions without runtime cost?

Is there a way to express that the condition in the contract has no side effect, so that it is always optimized out? Not likely. It’s known that you cannot take a big collection of assertions, turn them into assumptions (via __builtin_unreachable) and expect good results (e.g. Assertions Are Pessimistic, Assumptions Are Optimistic by John … Read more

Double question marks (‘??’) vs if when assigning same var

Don’t worry about the performance, it will be negligible. If you are curious about it, write some code to test the performance using Stopwatch and see. I suspect you’ll need to do a few million iterations to start seeing differences though. You can also never assume about the implementation of things, they are liable to … Read more

Should I use const for local variables for better code optimization?

Or am I wrong, and compilers can figure out by themselves that the local variable is never modified? Most of the compilers are smart enough to figure this out themselves. You should rather use const for ensuring const-correctness and not for micro-optimization. const correctness lets compiler help you guard against making honest mistakes, so you … Read more

Does C/C++ offer any guarantee on minimal execution time?

No, time spent does not count as observable behaviour to be protected by the as-if rule: [C++14: 1.8/5]: A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible executions of the corresponding instance of the abstract machine with the same program and the same input. However, if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)