[Bug rtl-optimization/70467] New: Useless "and [esp],-1" emitted on AND with uint64_t variable

b7.10110111 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Mar 30 18:59:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70467

            Bug ID: 70467
           Summary: Useless "and [esp],-1" emitted on AND with uint64_t
                    variable
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b7.10110111 at gmail dot com
  Target Milestone: ---

Consider the following C code:

#include <string.h>
long double __attribute__((noinline)) test() { return 0; }

long double doStuff()
{
    long double value=test();
    unsigned long long v;
    memcpy(&v,&value,sizeof v);
    v&=~(1ull<<63);
    memcpy(&value,&v,sizeof v);
    return value;
}
int main(){}

I get the following output for duStuff() function when I compile this code with
`gcc -O3 -fomit-frame-pointer -m32`:


doStuff:
        sub     esp, 28
        call    test       ; OK, I asked to avoid inlining it
        fstp    TBYTE PTR [esp]
        and     DWORD PTR [esp], -1           ; DO NOTHING!!!
        and     DWORD PTR [esp+4], 2147483647 ; Clear highest bit
        fld     TBYTE PTR [esp]
        add     esp, 28
        ret


The instruction marked with `DO NOTHING!!!` is a no-op here (flags are not
tested) and should have been eliminated.

This useless instruction is generated across generations of GCC starting at
least with 4.4.7 and ending at 6.0.0 20160221 (the snapshot testable at
gcc.godbolt.org).


More information about the Gcc-bugs mailing list