NO

Author Topic: optimization bug  (Read 2493 times)

czerny

  • Guest
optimization bug
« on: July 19, 2011, 05:22:34 PM »
Hallo,

I can understand that for a loop like


int k = 6;

do  k--;  while (k);


may and should not be produced any code by the compiler. Speed and size optimizations do this.

But the dowhile loop in the following function
 

//#pragma optimize(none)

long HTfreePos(HTAB *ht, long keylng)
{
   short int i;
   long oldsize, p;


   do {

//#pragma optimize()

      p = keylng & BITS[ht->bits];
      if ( NULL == ht->kvt[p].key ) return p; // 1. Versuch und Treffer!
      p = (p + FIRSTJMP) & BITS[ht->bits];
      if ( NULL == ht->kvt[p].key ) return p; // 2. Versuch und Treffer!
      p = (p + SECONDJMP) & BITS[ht->bits];
      if ( NULL == ht->kvt[p].key ) return p; // 3. Versuch und Treffer!

      // Wir verdoppeln das Dictionary

      if ( 31 > ht->bits ) {
         ht->bits++;
         oldsize = ht->size;
         ht->size <<= 1;
         ht->kvt    = realloc(ht->kvt, ht->size*sizeof(KV));

         if ( !ht) HTerror("could'nt allocate memory");

         for ( i = 0; i < oldsize; i++ )
            if ( ht->kvt.hsh & BITS[ht->bits] != i ) {
               ht->kvt[i + oldsize].hsh   = ht->kvt.hsh;
               ht->kvt[i + oldsize].key   = ht->kvt.key;
               ht->kvt[i + oldsize].val   = ht->kvt.val;
               ht->kvt.hsh = -1;
               ht->kvt.key = ht->kvt.val = NULL;
            } else {
               ht->kvt[i + oldsize].hsh = -1;
               ht->kvt[i + oldsize].key = ht->kvt.val = NULL;
            }
      }
   } while (1);
}


is ignored too. This is in my opinion a bug!

Question: With the pragmas enabled in the above code, when is optimization again switched on? Directly after the 'do' or at the end of the function?

czerny

CommonTater

  • Guest
Re: optimization bug
« Reply #1 on: July 20, 2011, 03:28:55 AM »
Ok, first do a read of the Bug Reports forum... I believe something very similar to this is already reported...

Second, what version of PC are you using?  A newer version may have it fixed.

Finally... If you can demonstrate which combinations of compiler switches (etc) the problem occurs under, I'd say you should escallate it to a bug report...

czerny

  • Guest
Re: optimization bug
« Reply #2 on: July 20, 2011, 10:05:02 PM »
You are right, I forgot this informations.

I use 6.50.8 R4 32 bit

the following switches:

-Tx86-coff -Zi -Ot -Ob1 -fp:precise -W1 -Gd

czerny