[Bug c/90356] New: Missed optimization for variables initialized to 0.0

noone@turm-lahnstein.de gcc-bugzilla@gcc.gnu.org
Sun May 5 19:39:00 GMT 2019


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

            Bug ID: 90356
           Summary: Missed optimization for variables initialized to 0.0
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: noone@turm-lahnstein.de
  Target Milestone: ---

For the following example:

float doit(float k){
    float c[2]={0.0};
    c[1]+=k;
    return c[0]+c[1];
}

the resulting assembler (-O2) is (https://gcc.godbolt.org/z/sSi9OC):

doit:
        pxor    %xmm1, %xmm1
        addss   %xmm1, %xmm0
        addss   %xmm1, %xmm0
        ret

but should be more like:

doit:                                   # 
        pxor    %xmm1, %xmm1  ; or maybe xorps
        addss   %xmm1, %xmm0
        retq


because c[0] is 0.0.


More information about the Gcc-bugs mailing list