Compiler problems and engine degradation

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

sovaz1997
Posts: 261
Joined: Sun Nov 13, 2016 10:37 am

Compiler problems and engine degradation

Post by sovaz1997 »

Have you ever had such situations?

After updating the system, the same version of the engine suddenly became degraded (gradually playing worse and worse)

Cutechess-cli, MinGW/gcc

It's start normally but the more games, the worse the engine plays. Same versions!

Code: Select all

Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 1 - 0 - 3  [0.625] 4
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 3 - 7 - 11  [0.405] 21
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 4 - 8 - 13  [0.420] 25
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 5 - 8 - 14  [0.444] 27
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 6 - 9 - 14  [0.448] 29
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 7 - 18 - 19  [0.375] 44
...
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 7 - 64 - 43  [0.250] 114 (!)
All versions of the engine on a new compiler degrade over time. If someone had such a problem, I will be grateful for the advice. Thank! :)
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.5 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
sovaz1997
Posts: 261
Joined: Sun Nov 13, 2016 10:37 am

Re: Compiler problems and engine degradation

Post by sovaz1997 »

1+0.01: same results

Code: Select all

Score of Zevra v2.1 r210 vs Zevra v2.1.1 r216: 4 - 4 - 1  [0.500] 9
Score of Zevra v2.1 r210 vs Zevra v2.1.1 r216: 9 - 29 - 8  [0.283] 46
Score of Zevra v2.1.1 r216 vs Zevra v2.1.1 r216: 19 - 185 - 32  [0.148] 236
Score of Zevra v2.1 r210 vs Zevra v2.1.1 r216: 20 - 225 - 35  [0.134] 280
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.5 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Compiler problems and engine degradation

Post by Ras »

I have checked the current master with CppCheck (free open source tool - highly recommended), and there's a couple of potential issues:

Code: Select all

[bitboards.c:167]: (error) Shifting by a negative value is undefined behaviour
[bitboards.c:168]: (error) Shifting by a negative value is undefined behaviour
[bitboards.c:164]: (error) Shifting 64-bit value by 72 bits is undefined behaviour
[bitboards.c:165]: (error) Shifting 64-bit value by 70 bits is undefined behaviour
[bitboards.c:167]: (warning) Suspicious code: sign conversion of - in calculation, even though - can have a negative value
[bitboards.c:168]: (warning) Suspicious code: sign conversion of - in calculation, even though - can have a negative value
[eval.c:272]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.
[eval.c:273]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.
[eval.c:274]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.
[board.c:97]: (warning) %lx in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned long long'.
[board.c:444]: (style) Opposite expression on both sides of '&'.
[transposition.c:21]: (error) Common realloc mistake: 'tt' nulled but not freed upon failure
[timemanager.h:36] -> [timemanager.c:26]: (style, inconclusive) Function 'createFixedNodesTm' argument 1 names different: declaration 'depth' definition 'nodes'.
[uci.c:195]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'unsigned long long'.
[uci.c:195]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'unsigned long long'.
[search.c:27]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned long long'.
[search.c:27]: (warning) %lu in format string (no. 2) requires 'unsigned long' but the argument type is 'unsigned long long'.
[search.c:414]: (warning) %lu in format string (no. 2) requires 'unsigned long' but the argument type is 'unsigned long long'.
[search.c:437]: (warning) %lu in format string (no. 2) requires 'unsigned long' but the argument type is 'unsigned long long'.
[search.c:502]: (style) The scope of the variable 'j' can be reduced.
[search.c:502]: (style) The scope of the variable 'key' can be reduced.
[search.c:503]: (style) The scope of the variable 'keyMove' can be reduced.
Especially the undefined behaviour is dangerous because it means the compiler is free to generate any code, actually for the whole program and not only the impacted function. GCC has a track record of ever more aggressive optimisations that rely on the absence of any undefined behaviour.

Also, I would benchmark the engine with and without strict pointer aliasing. If there is no considerable performance hit when you disable strict pointer aliasing, I would leave it disabled. In practice, the involved risk of undefined behaviour is more risky than what it's worth, at least for releases.

Next, if you are under Linux, have a look at GCC's ton of "sanitizer" options, and use all of them - including the pointer aliasing checks.
Rasmus Althoff
https://www.ct800.net
sovaz1997
Posts: 261
Joined: Sun Nov 13, 2016 10:37 am

Re: Compiler problems and engine degradation

Post by sovaz1997 »

Thanks for such a detailed answer! I'll try to find errors. I just tested Stockfish just in case and it hasn't such problems, which means that I have a problem in my code.
Zevra 2 is my chess engine. Binary, source and description here: https://github.com/sovaz1997/Zevra2
Zevra v2.5 is last version of Zevra: https://github.com/sovaz1997/Zevra2/releases
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Compiler problems and engine degradation

Post by jdart »

There are occasionally performance regression bugs in gcc, but as noted it is more likely there is a problem in your code.

--Jon