Hi! The following testcase shows different behavior between -g and -g0 in constprop_register, if a flags register setter is separated from a conditional jump using those flags with -g by a DEBUG_INSN. As it uses just NEXT_INSN, for -g it will look at the DEBUG_INSN which is not a conditional jump, while otherwise it would look at the conditional jump and call cprop_jump.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/11.2/10.4? 2021-04-20 Jakub Jelinek <ja...@redhat.com> PR rtl-optimization/100148 * cprop.c (constprop_register): Use next_nondebug_insn instead of NEXT_INSN. * g++.dg/opt/pr100148.C: New test. --- gcc/cprop.c.jj 2021-01-04 10:25:39.000000000 +0100 +++ gcc/cprop.c 2021-04-20 13:48:28.691450016 +0200 @@ -1007,16 +1007,18 @@ static int constprop_register (rtx from, rtx src, rtx_insn *insn) { rtx sset; + rtx_insn *next_insn; /* Check for reg or cc0 setting instructions followed by conditional branch instructions first. */ if ((sset = single_set (insn)) != NULL - && NEXT_INSN (insn) - && any_condjump_p (NEXT_INSN (insn)) && onlyjump_p (NEXT_INSN (insn))) + && (next_insn = next_nondebug_insn (insn)) != NULL + && any_condjump_p (next_insn) + && onlyjump_p (next_insn)) { rtx dest = SET_DEST (sset); if ((REG_P (dest) || CC0_P (dest)) - && cprop_jump (BLOCK_FOR_INSN (insn), insn, NEXT_INSN (insn), + && cprop_jump (BLOCK_FOR_INSN (insn), insn, next_insn, from, src)) return 1; } --- gcc/testsuite/g++.dg/opt/pr100148.C.jj 2021-04-20 15:32:31.820489909 +0200 +++ gcc/testsuite/g++.dg/opt/pr100148.C 2021-04-20 15:32:06.376770658 +0200 @@ -0,0 +1,27 @@ +// PR rtl-optimization/100148 +// { dg-do compile } +// { dg-options "-O2 -fno-dce -fno-tree-dce -fno-tree-dominator-opts -fno-tree-sink -fcompare-debug" } + +int i; +enum E { } e, ee; + +bool +baz (int) +{ + return ee; +} + +bool bar (); +bool a, b; + +void +foo () +{ + switch (ee) + { + case 0: + e = E (a ? : i); + case 1: + !(b || baz (0) && bar ()); + } +} Jakub