https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82024
Bug ID: 82024 Summary: [8 Regression] wrong code with -Og -fgcse-sm -frerun-cse-after-loop --param=max-combine-insns=3 Product: gcc Version: 8.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 42079 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42079&action=edit reduced testcase Output: $ x86_64-pc-linux-gnu-gcc -Og -fgcse-sm -frerun-cse-after-loop --param=max-combine-insns=3 testcase.c $ ./a.out Aborted $ 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-251387-checking-yes-rtl-df-extra-nographite-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.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 --without-cloog --without-ppl --without-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-251387-checking-yes-rtl-df-extra-nographite-amd64 Thread model: posix gcc version 8.0.0 20170828 (experimental) (GCC) .combine does: ... Trying 13, 12 -> 14: ... Successfully matched this instruction: (set (reg:DI 106) (const_int 0 [0])) Successfully matched this instruction: (set (reg:DI 105) (plus:DI (reg/v:DI 101 [ eD.1821 ]) (reg:DI 103))) allowing combination of insns 12, 13 and 14 original costs 4 + 4 + 0 = 0 replacement costs 4 + 4 = 8 deferring deletion of insn with uid = 12. modifying insn i2 13: r106:DI=0 deferring rescan insn with uid = 13. modifying insn i3 14: r105:DI=r101:DI+r103:DI REG_DEAD r101:DI REG_DEAD r103:DI deferring rescan insn with uid = 14. ... Trying 14, 13 -> 20: Successfully matched this instruction: (set (reg:DI 105) (plus:DI (reg/v:DI 101 [ eD.1821 ]) (reg:DI 103))) allowing combination of insns 13, 14 and 20 original costs 4 + 4 + 6 = 14 replacement cost 4 deferring rescan insn with uid = 20. deferring deletion of insn with uid = 14. deferring deletion of insn with uid = 13. modifying insn i3 20: r105:DI=r101:DI+r103:DI REG_DEAD r103:DI REG_DEAD r101:DI deferring rescan insn with uid = 20. ... which results in: ... (insn 17 16 20 2 (parallel [ (set (reg/v:DI 100 [ <retval> ]) (plus:DI (reg:DI 107 [ _2 ]) (reg:DI 105))) (clobber (reg:CC 17 flags)) ]) "testcase.c":16 218 {*adddi_1} (expr_list:REG_DEAD (reg:DI 107 [ _2 ]) (expr_list:REG_DEAD (reg:DI 105) (expr_list:REG_UNUSED (reg:CC 17 flags) (nil))))) (insn 20 17 25 2 (set (reg:DI 105) (plus:DI (reg/v:DI 101 [ eD.1821 ]) (reg:DI 103))) "testcase.c":18 214 {*leadi} (expr_list:REG_DEAD (reg:DI 103) (expr_list:REG_DEAD (reg/v:DI 101 [ eD.1821 ]) (nil)))) ... insn 17 uses r105, which is now set in insn 20, which appears after it