https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86438
Bug ID: 86438 Summary: [8/9 Regression] wrong code at -Os Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zsojka at seznam dot cz Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu Created attachment 44365 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44365&action=edit reduced testcase Output: $ x86_64-pc-linux-gnu-gcc -Os testcase.c $ ./a.out Aborted Diff between -O2 -> -Os shows: @@ -77,15 +76,15 @@ # testcase.c:13: u32 f = __builtin_sub_overflow_p (d, (u128) d, (u64)0); mov ebx, 0 # _2, # testcase.c:12: u64 d = (g ? 5 : 4); - setne al #, iftmp.0_9 - movzx eax, al # iftmp.0_9, iftmp.0_9 - add rax, 4 # iftmp.0_9, + cmp rax, 1 # tmp100, + sbb rax, rax # iftmp.0_9 + add rax, 5 # iftmp.0_9, # testcase.c:13: u32 f = __builtin_sub_overflow_p (d, (u128) d, (u64)0); mov rcx, rax # _2, iftmp.0_9 setc al #, _11 The - (-O2) never sets CF (thus the last setc always sets al=0). The + (-Os) set CF if g==0 (thus the last setc sets al=(g==0)). The __builtin_sub_overflow_p() in fact never overflows, because it does (u64)d-(u128)d == 0 in all cases. $ x86_64-pc-linux-gnu-gcc -v Using built-in specs. COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-262509-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++ --enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra --disable-bootstrap --with-cloog --with-ppl --with-isl --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld --with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch --prefix=/repo/gcc-trunk//binary-trunk-262509-checking-yes-rtl-df-extra-nobootstrap-amd64 Thread model: posix gcc version 9.0.0 20180709 (experimental) (GCC)