Microsoft KB Archive/234511

From BetaArchive Wiki

Article ID: 234511

Article Last Modified on 8/7/2007



APPLIES TO

  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q234511

SYMPTOMS

The Visual C++ 6.0 compiler does not remove certain unneeded temporary instructions, which can slow down code execution.

RESOLUTION

A supported fix for Visual C++ 6.0 that corrects this problem is now available from Microsoft, but it has not been fully regression tested and should be applied only to systems experiencing this specific problem.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, visit the following Web site:

The English version of this fix should have the following file attributes or later.

Name Size Date Time Version# Platform
c1xx.dll 1,169KB 6/4/99 11:01 PM 12.00.8520.0 x86



STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This bug was corrected in the next service pack for Visual Studio 6.0.

For more information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio service Pack Is Installed


To download the latest Visual Studio service pack, visit the following Microsoft Web site:

MORE INFORMATION

Steps to reproduce the behavior

Compile the following code with /O2 in Visual C++ 6.0:

#include <time.h>
#include <stdio.h> 

class boo
{
    int a;
    int b;
    int c;
    int d;

public:
    boo():
      a(0), b(0), c(0), d(0) {}

    boo(int x):
      a(x), b(x), c(x), d(x) {}
};

boo fun(int x)
{
    if (x)
        return boo(x);
    else
        return boo();
}

void main()
{
    time_t   start, finish; 
    double   elapsed_time;
         
    int i;
     time( &start );
    for (i=0; i<200000000; i++)
    {
        fun(0);
    }
    for (i=0; i<200000000; i++)
    {
        fun(10);
    }
    time( &finish );
    elapsed_time = difftime( finish, start );
    printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
}
                

And compare the following snippet of the generated code:

; 21   :    if (x)

    mov ecx, DWORD PTR _x$[esp-4]
    test    ecx, ecx
    je  SHORT $L622

; 22   :        return boo(x);

    mov eax, DWORD PTR ___$ReturnUdt$[esp-4]
    mov edx, eax
    mov DWORD PTR [edx], ecx
    mov DWORD PTR [edx+4], ecx
    mov DWORD PTR [edx+8], ecx
    mov DWORD PTR [edx+12], ecx

; 25   : }

    ret 0
$L622:

; 23   :    else
; 24   :        return boo();

    mov eax, DWORD PTR ___$ReturnUdt$[esp-4]
    push    ebx
    mov ebx, eax
    xor ecx, ecx
    xor edx, edx
    push    esi
    mov DWORD PTR [ebx], ecx
    xor esi, esi
    push    edi
    xor edi, edi
    mov DWORD PTR [ebx+4], edx
    mov DWORD PTR [ebx+8], esi
    mov DWORD PTR [ebx+12], edi
    pop edi
    pop esi
    pop ebx

; 25   : }

    ret 0
                

With that generated by Visual C++ 5.0 when compiled with /O2:

; 21   :    if (x)

    mov ecx, DWORD PTR _x$[esp-4]

; 22   :        return boo(x);

    mov eax, DWORD PTR ___$ReturnUdt$[esp-4]
    xor edx, edx
    cmp ecx, edx
    je  SHORT $L547
    mov DWORD PTR [eax], ecx
    mov DWORD PTR [eax+4], ecx
    mov DWORD PTR [eax+8], ecx
    mov DWORD PTR [eax+12], ecx

; 25   : }

    ret 0
$L547:

; 23   :    else
; 24   :        return boo();

    mov DWORD PTR [eax], edx
    mov DWORD PTR [eax+4], edx
    mov DWORD PTR [eax+8], edx
    mov DWORD PTR [eax+12], edx

; 25   : }

    ret 0
                

The Visual C++ 6.0 version of the code contains more instructions, which can slow down program execution. The executable built with Visual C++ 6.0 runs slower than the one built with Visual C++ 5.0 on a comparable system.


Additional query words: sp4 code generation performance slow codegen

Keywords: kbhotfixserver kbqfe kbqfe kbbug kbcompiler kbfix kbvs600sp4fix kbvs600sp5fix KB234511