https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88481
Bug ID: 88481
Summary: -O1 causes optimizer to drop 'then' clause in
conditional
Product: gcc
Version: 8.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: heinrich.seebauer at swistec dot de
Target Milestone: ---
Compiling with option -O1 causes the optimizer to drop code for the 'then'
branch.
Verified for targets
gnueabi-linux (host=x86/linux, target=arm/linux), and
x86 (native)
Compilation produces correct results with options -O0, -O2, -O3, -Os.
If -O1 options
-fdefer-pop
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers
-floop-optimize
-fif-conversion
-fif-conversion2
-ftree-ccp
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-ter
-ftree-lrs
-ftree-sra
-ftree-copyrename
-ftree-fre
-ftree-ch
-funit-at-a-time
-fmerge-constants
are used, the result is correct. However, adding -O1 to this list of options
results in the missing code.
-
the exact version of GCC:
gcc --version
gcc (SUSE Linux) 8.2.1 20181108 [gcc-8-branch revision 265914]
the options given when GCC was configured/built:
unknown
the complete command line that triggers the bug:
gcc -D_GNU_SOURCE=1 -D_POSIX_SOURCE=1 -DDEBUG=1 -DWITH_MBEDTLS=1 -DTARGET=PC
-I.././inc -I../modelSource -I../../libiec61850/config
-I../../libiec61850/src/logging -I../../libiec61850/src/hal/inc
-I../../libiec61850/src/common/inc -I../../libiec61850/src/mms/inc
-I../../libiec61850/src/iec61850/inc
-I../../libiec61850/src/iec61850/inc_private
-I../../libiec61850/src/mms/inc_private -I../../libiec61850/third_party/sqlite
-I../../libiec61850/third_party/mbedtls/include -I../../libiec61850/src/tls
-I../../libiec61850/src/tls/mbedtls -I../../libiec61850/src/mms/iso_mms/asn1c
-O1 -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -g -Wall -c
-fmessage-length=0 -MMD -MP -MF"src/runtime/actPow_ggioRt.d"
-MT"src/runtime/actPow_ggioRt.o" -o "src/runtime/actPow_ggioRt.o"
"../src/runtime/actPow_ggioRt.c"
the compiler output (error messages, warnings, etc.):
gcc -D_GNU_SOURCE=1 -D_POSIX_SOURCE=1 -DDEBUG=1 -DWITH_MBEDTLS=1 -DTARGET=PC
-I.././inc -I../modelSource -I../../libiec61850/config
-I../../libiec61850/src/logging -I../../libiec61850/src/hal/inc
-I../../libiec61850/src/common/inc -I../../libiec61850/src/mms/inc
-I../../libiec61850/src/iec61850/inc
-I../../libiec61850/src/iec61850/inc_private
-I../../libiec61850/src/mms/inc_private -I../../libiec61850/third_party/sqlite
-I../../libiec61850/third_party/mbedtls/include -I../../libiec61850/src/tls
-I../../libiec61850/src/tls/mbedtls -I../../libiec61850/src/mms/iso_mms/asn1c
-O1 -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -g -Wall -c
-fmessage-length=0 -MMD -MP -MF"src/iec61850/fsch.d" -MT"src/iec61850/fsch.o"
-o "src/iec61850/fsch.o" "../src/iec61850/fsch.c"
Finished building: ../src/iec61850/fsch.c
the preprocessed file: see attachment
-
source code snippet:
...
fsch.c:423: if (forwardBackwardDiff < 0)
fsch.c:427: timeMatchedSec += SECONDS_PER_HOUR;
...
if condition (forwardBackwardDiff < 0) is true, the addition is not executed.
Disassembly shows that no code has been generated for line 427. Debugging shows
that the code line is effectively skipped, though the condition is true.
gdb disassembly:
423 if (forwardBackwardDiff < 0)
00409111: lea 0xe10(%r12),%rax
00409119: pxor%xmm1,%xmm1
0040911d: comisd %xmm0,%xmm1
00409121: cmova %rax,%r12
429 strTmRt->nextStartTimeSec=timeMatchedSec;
00409125: mov %r12,0x28(%rbx)
430
strTmRt->prevStartTimeSec=timeMatchedSec-SECONDS_PER_HOUR;
00409129: lea -0xe10(%r12),%rdi
00409131: mov %rdi,0x20(%rbx)