https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105558
Bug ID: 105558 Summary: simple 8-byte integer calculation fails with -O3 / march=core-avx2 on some gfortran 8/9/10 versions Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: federico.perini at gmail dot com Target Milestone: --- Created attachment 52950 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52950&action=edit integer(1) test program Hi gcc/gfortran team, I have two routines that encode and decode two integer(1) IDs (in [1:6] and [1:32] respectively) to a unique 8-byte integer(1), for 192 possible cases. The example that fails should behave like encode(1, 32) returns 77 decode(77) returns [1, 32] but returns either [-5, 33] or sometimes [3,71] With -O3, there are both versions and architectures of gfortran that either work or not. On godbolt (https://godbolt.org/z/5GboahWs1), this is what I see: gfortran | -O3 -mtune=generic | -O3 -march=core-avx2 | 12.1 | OK | OK | 11.3 | OK | OK | 11.2 | OK | OK | 11.1 | OK | OK | 10.3 | OK | ERROR | 10.2 | OK | ERROR | 10.1 | OK | ERROR | 9.4 | OK | ERROR | 9.3 | OK | ERROR | 9.2 | OK | ERROR | 9.1 | OK | ERROR | 8.5 | ERROR | ERROR | 8.4 | ERROR | ERROR | 8.3 | ERROR | ERROR | 8.2 | ERROR | ERROR | 8.1 | ERROR | ERROR | 7.3 | OK | OK | 7.2 | OK | OK | 7.1 | OK | OK | 6.3 | OK | OK | 5.5 | OK | OK | Also note that: - problem is with int8 only; all is OK with int16,int32,int64 - no problems with -O2. I'm attaching the code here as well, thank you, Federico