Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal 0x0d0a's Journal: Gcc 3.3.3 optimization

I'm putting this in my journal instead of a Slashdot post because the lameness filter keeps eating my Slashdot post. If you have a response, please just respond to my Slashdot post.

I was empirically analyzing the gcc 3.3.3 optimizer a couple of days ago. Some interesting points:

* gcc does not appear to take advantage of the iso c99 "restrict" keyword, which can allow for significant performance improvements. The "restrict" keyword allows one to indicate to the compiler that a pointer is not an "alias" (pointer to the same location) as any other pointer available to the function, nor does it point to anything that points to anything and so forth that is aliased. Without this hinting, C compilers have a very difficult time dealing with optimizations across function calls.

* I can't seem to find any way to convince gcc to dump out its parse tree before doing any optimization. It'd be nice if I could convince it to do so -- I *know* that there's something less processed than -dr output.

* The following main() code optimizes rather entertainingly:
c=0;
if (argc == 6) {
c++;
if ((argc % 6) == 0)
c++;}
return c;

Compiles to (non-pertient sections removed):


                xorl %ecx, %ecx
                cmpl $6, %eax
                je .L4
L2:
                movl %ecx, %eax
                leave
                ret .p2align 2,,3
L4:
                cltd
                idivl %eax
                testl %edx, %edx
                movl $1, %ecx
                jne .L2
                movl $2, %ecx
                jmp .L2

Now, gcc's optimizer is clearly clever enough to figure out that argc has the value 6. However, it takes advantage of that fact...by using argc to divide argc! These two conditionals should have compiled down to cmpl, je, mov, jmp, mov, ret.

And it should be the law: If you use the word `paradigm' without knowing what the dictionary says it means, you go to jail. No exceptions. -- David Jones

Working...