Live data from Hacker News

What Are Your GCC Flags?

blog.httrack.com

111–117 of 117 posts

Re: What Are Your GCC Flags?

#111
post #95

Earlier quoted context omitted.

You'd have to use annotations or asserts. Or rely on literal whole program analysis to prove upper bounds of parameters/etc (which still may not be possible statically) Otherwise, given as something as simple as for (unsigned i = 0; i You can't say it iterates N/2 times

I took a couple examples where gcc failed vectorization for unsigned indexes and tried to rewrite them in a way that didn't sacrifice 1/2 of the type's range just to satisfy the optimizer. In the first example I could just change a " The results: http://ideone.com/7vidIs Generated code http://tinyurl.com/le72k4o

If you change Think of n == UNSIGNED_MAX. n+1 will overflow.

Re: What Are Your GCC Flags?

#112

"-Winit-self" actually disables the common "var x = x" idiom which is used to silence "uninitialized variable" warnings. Personally I consider "-Werror" stupid. Warnings are designed to help and be reviewed, but aiming at "100% warning free" code should not be an "aim". For instance, I'd rather have "unitialized warnings" than use "i = i", which you know, might actually be correct code if "i" was available in scope a…

If you're using var x = x; then stop. The compiler is able to validate that assignment to variables are never used using data flow analysis, so always initializing has no cost once optimizations are turned on. Beside, even if it was not optimized away, until a profiler actualy shows that a variable initialization is your bottleneck, it's a waste of time and will make code refactoring harder and cuase bug down the lin…

I think you misunderstood the point. The discussion var x = x has nothing to do about performance.

Re: What Are Your GCC Flags?

#114
post #95

Earlier quoted context omitted.

I took a couple examples where gcc failed vectorization for unsigned indexes and tried to rewrite them in a way that didn't sacrifice 1/2 of the type's range just to satisfy the optimizer. In the first example I could just change a " The results: http://ideone.com/7vidIs Generated code http://tinyurl.com/le72k4o

If you change Think of n == UNSIGNED_MAX. n+1 will overflow.

Right, but the same is true of signed as well.

Re: What Are Your GCC Flags?

#115

Earlier quoted context omitted.

If you change Think of n == UNSIGNED_MAX. n+1 will overflow.

Right, but the same is true of signed as well.

The issue i raised is that you replaced a perfectly functioning loop with one that does not work properly (it does iterate the same number of times for all inputs)

You said "I can change Both are well defined to occur. You cannot change the loop behavior and say you have the same loop :)

Re: What Are Your GCC Flags?

#116

Earlier quoted context omitted.

Right, but the same is true of signed as well.

The issue i raised is that you replaced a perfectly functioning loop with one that does not work properly (it does iterate the same number of times for all inputs) You said "I can change Both are well defined to occur. You cannot change the loop behavior and say you have the same loop :)

I never meant to imply that changing "<= n" to "!= n + 1" does not change the semantics of the unsigned loop. This was an example shown in some LLVM documentation as to why you should use signed loop variables. I was just showing that you can still use unsigned variables, have the same semantics as _the signed loop_ ,and get vectorized code.
Post reply on HN