modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/loop-ivopts-2.c (about)

     1  /* PR rtl-optimization/20290  */
     2     
     3  /* We used to mis-optimize the second loop in main on at least ppc and
     4     arm, because tree loop would change the loop to something like:
     5  
     6    ivtmp.65 = &l[i];
     7    ivtmp.16 = 113;
     8    goto <bb 4> (<L4>);
     9  
    10  <L3>:;
    11    *(ivtmp.65 + 4294967292B) = 9;
    12    i = i + 1;
    13  
    14  <L4>:;
    15    ivtmp.16 = ivtmp.16 - 1;
    16    ivtmp.65 = ivtmp.65 + 4B;
    17    if (ivtmp.16 != 0) goto <L3>; 
    18  
    19    We used to consider the increment of i as executed in every
    20    iteration, so we'd miscompute the final value.  */
    21  
    22  extern void abort (void);
    23  
    24  void
    25  check (unsigned int *l)
    26  {
    27    int i;
    28    for (i = 0; i < 288; i++)
    29      if (l[i] != 7 + (i < 256 || i >= 280) + (i >= 144 && i < 256))
    30        abort ();
    31  }
    32  
    33  int
    34  main (void)
    35  {
    36    int i;
    37    unsigned int l[288];
    38  
    39    for (i = 0; i < 144; i++)
    40      l[i] = 8;
    41    for (; i < 256; i++)
    42      l[i] = 9;
    43    for (; i < 280; i++)
    44      l[i] = 7;
    45    for (; i < 288; i++)
    46      l[i] = 8;
    47    check (l);
    48    return 0;
    49  }
    50