From 404d0ca7820bbf258e2edfac423403ee31b48a7b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 1 Dec 2020 16:23:59 +0100 Subject: [PATCH] loop-invariant: JUMP_INSNs aren't loop invariant [PR97954] The following testcase ICEs because loop invariant motion moves asm goto with a single output as invariant. Normally, jumps aren't really moved, because if they are single set, they have their SET_DEST (pc) and pc_rtx has VOIDmode on which one of the functions find_invariant_insn calls bails out. The code already punts on insns that can throw or trap. And for asm goto without outputs, it isn't single set, or asm goto with two or more outputs it isn't single set either. 2020-12-01 Jakub Jelinek PR rtl-optimization/97954 * loop-invariant.c (find_invariant_insn): Punt on JUMP_P insns. * gcc.dg/pr97954.c: New test. --- gcc/loop-invariant.c | 4 ++++ gcc/testsuite/gcc.dg/pr97954.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr97954.c diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 37ae654..653e303 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 0000000..178e1d2 --- /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; +} -- 2.7.4