diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 37ae6549e56..653e3033271 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1099,6 +1099,10 @@ find_invariant_insn (rtx_insn *insn, bool always_reached, bool always_executed) if (HAVE_cc0 && sets_cc0_p (insn)) return; + /* Jumps have control flow side-effects. */ + if (JUMP_P (insn)) + return; + set = single_set (insn); if (!set) return; diff --git a/gcc/testsuite/gcc.dg/pr97954.c b/gcc/testsuite/gcc.dg/pr97954.c new file mode 100644 index 00000000000..178e1d2e965 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97954.c @@ -0,0 +1,12 @@ +/* PR rtl-optimization/97954 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +foo (void) +{ + int x; + lab: + asm goto ("": "=r" (x) : : : lab); + return x; +}