This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/68529] New: scev failed for while(i--)


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

            Bug ID: 68529
           Summary: scev failed for while(i--)
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: majun4950646 at 163 dot com
  Target Milestone: ---

loop distribution failed to generate memset library call for the following
example:

#include <stdio.h>
#include <stdlib.h>

int main(){
    char c[10000]={};

    unsigned int nchar=9999;

    while(nchar--!=0)
      {   
       c[nchar]='A';
      }   

    printf("%s\n",c);
    return 0;
}


Compiled with 
gcc -O3 -march=core2  -fdump-tree-ldist-details  t.c -o t

From the ldist dump:

...
Creating dr for c[nchar_24]
analyze_innermost: failed: evolution of offset is not affine.
    base_address: 
    offset from base address: 
    constant offset from base address: 
    step: 
    aligned to: 
    base_object: c
    Access function 0: {9998, +, 4294967295}_1
...

and it failed to transform the while loop to memset

=====
However, it successed by change while(nchar--!=0) to  for(;nchar !=0;nchar--):

#include <stdio.h>
#include <stdlib.h>

int main(){
    char c[10000]={};

    unsigned int nchar=9999;

    for(;nchar!=0;nchar--)
      {   
       c[nchar]='A';
      }   

    printf("%s\n",c);
    return 0;
}

...

Creating dr for c[nchar_21]
analyze_innermost: success.
    base_address: &c
    offset from base address: 0
    constant offset from base address: 9999
    step: -1
    aligned to: 128 
    base_object: c
    Access function 0: {9999, +, 4294967295}_1
...
and generate memset library call stmt:
 __builtin_memset (&MEM[(void *)&c + 1B], 65, 9999);

I also testd in gcc4.8.4 and trunk, both failed.

--Jun

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]