Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Corruption due to inline optimization?

Intel_C_Intel
Employee
304 Views
Hi,

I have seen some curious problem in my code due to inline optimization by Intel Compiler 7.1 on WinXP platform.

I am not expert with assembly so can not fully appreciate what is going on here. If anyone can guide me or help me then it will be a great help.

I have a C++ code as below:
line 602- ;;; cosf(X::toRadians(render.getLightAzimuth())) *

Which with inline optimization corrupts the stack.

I have listed both unoptimized (works) and unoptimized (fails) assembly output. It seems to me that both calls different sin/cos functions.

Any suggestions what is going wrong??

Optimized version assembly output which _corrupts_ is as below:
--------------------------------------------------------------------------------
0020c d9 fb fsincos ;X.cpp:600.43
;;; sinf(lightElevation),
;;; cosf(V::toRadians(render.getLightAzimuth())) *
0020e 8b 45 bc mov eax, DWORD PTR [ebp-68] ;X.cpp:602.59
00211 8b 50 04 mov edx, DWORD PTR [eax+4] ;X.cpp:602.59

$LN247:
00240 ff b2 e8 08 04
00 push DWORD PTR [edx+264424] ;X.cpp:602.59
00246 e8 fc ff ff ff call ?toRadiXXXXXXX ;X.cpp:602.59
; LOE f1
.B10.102: ; Preds .B10.17
0024b 83 c4 0c add esp, 12 ;X.cpp:602.59
; LOE f1
.B10.18: ; Preds .B10.102
0024e d9 ff fcos ;X.cpp:602.59

$LN249:
0025a d9 5d a8 fstp DWORD PTR [ebp-88] ;X.cpp:602.59
0025d f3 0f 10 45 a8 movss xmm0, DWORD PTR [ebp-88] ;X.cpp:602.59

--------------------------------------------------------------------------------

Un-optimized version which DOES NOT corrupt stack is:

;;; cosf(X::toRadians(render.getLightAzimuth())) *

0033c 8b 4d ac mov ecx, DWORD PTR [ebp-84] ;X.cpp:602.59
0033f e8 fc ff ff ff call ?getLightAzimuth@@@@@ ;X.cpp:602.59
; LOE f1
.B463.51: ; Preds .B463.50
00344 57 push edi ;X.cpp:602.59
00345 d9 1c 24 fstp DWORD PTR [esp] ;X.cpp:602.59
00348 e8 fc ff ff ff call ?toRadians@@@Z ;X.cpp:602.59
; LOE f1
.B463.160: ; Preds .B463.51
0034d 59 pop ecx ;X.cpp:602.59
; LOE f1
.B463.52: ; Preds .B463.160
0034e 57 push edi ;X.cpp:602.59
0034f d9 1c 24 fstp DWORD PTR [esp] ;X.cpp:602.59
00352 e8 fc ff ff ff call _cosf ;X.cpp:602.59
; LOE f1
.B463.161: ; Preds .B463.52
00357 dd 5d b0 fstp QWORD PTR [ebp-80] ;X.cpp:602.59
0035a 83 c4 04 add esp, 4 ;X.cpp:602.59
; LOE
.B463.53: ; Preds .B463.161
$LN3452:

0 Kudos
1 Reply
JenniferJ
Moderator
304 Views

Please file an issue to premier support with the .i file (that contains the code of above) and compile options. To get the .i file, add -EP -P to the compile option.

To get going, try to compile this file with -Ob0 or add "__declspec(noinline)" to function "render.getLightAzimuth()".

Thank you,

Jennifer

0 Kudos
Reply