When optimizations make the code worse, aka GCC and Clang are fucking retarded.

Both GCC and Clang are obsessed with constant / value range propagation. Unfortunately they are far too stupid to actually apply such optimizations appropriately. A common pattern that both compilers completely fuck up is testing a pointer for NULL and then returning NULL. Now anyone who is not completely retarded would realize that they had a nice NULL already sitting in the register and just return that but these so called smart optimizing compilers are so fucking stupid they explicitly set the register to NULL even though it was already NULL. This is only one example of hundreds of cases where the compiler does really retarded shit that even a literal retard would not do. Fuck, I spend more time fighting the stupid compiler than actually being productive. I have heard people say that modern compilers produce better assembly than humans but this is the biggest lump of shit that has ever been spouted from someones mouth. It would not be so bad if these issues happened only occasionally, but no, almost every function is effected and it drives me mental. Fix your stupid compilers.

void* test(void);
void* test2(void)
{
    void* tmp = test();
    if(tmp == NULL)
        return tmp;
    return test();
}

Output of GCC and Clang

test2:
        call    test
        testl   %eax, %eax
        je      .L1
        jmp     test
.L1:
        xorl    %eax, %eax
        ret

Output of MSVC for comparison.
This is how it should be compiled.

_test2  PROC
        call    _test
        test    eax, eax
        jne     SHORT $LN2@test2
        ret     0
$LN2@test2:
        jmp     _test
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *