diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index d36dfc842e15f363a238c33c0cb86691f7fdef21..eef565eddb5dc7195542e85154b8f3566adac304 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -3687,7 +3687,7 @@ expand_asm_stmt (gasm *stmt) copy = get_insns (); end_sequence (); } - insert_insn_on_edge (copy, e); + prepend_insn_to_edge (copy, e); } } } diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc index a8549d5f986417aafabf8e62900af48e8a261172..15259c5e98478a97c343591d6f0370f2df5a262f 100644 --- a/gcc/cfgrtl.cc +++ b/gcc/cfgrtl.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see - CFG-aware instruction chain manipulation delete_insn, delete_insn_chain - Edge splitting and committing to edges - insert_insn_on_edge, commit_edge_insertions + insert_insn_on_edge, prepend_insn_to_edge, commit_edge_insertions - CFG updating after insn simplification purge_dead_edges, purge_all_dead_edges - CFG fixing after coarse manipulation @@ -1966,7 +1966,8 @@ rtl_split_edge (edge edge_in) /* Queue instructions for insertion on an edge between two basic blocks. The new instructions and basic blocks (if any) will not appear in the - CFG until commit_edge_insertions is called. */ + CFG until commit_edge_insertions is called. If there are already + queued instructions on the edge, PATTERN is appended to them. */ void insert_insn_on_edge (rtx pattern, edge e) @@ -1986,6 +1987,25 @@ insert_insn_on_edge (rtx pattern, edge e) end_sequence (); } +/* Like insert_insn_on_edge, but if there are already queued instructions + on the edge, PATTERN is prepended to them. */ + +void +prepend_insn_to_edge (rtx pattern, edge e) +{ + /* We cannot insert instructions on an abnormal critical edge. + It will be easier to find the culprit if we die now. */ + gcc_assert (!((e->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (e))); + + start_sequence (); + + emit_insn (pattern); + emit_insn (e->insns.r); + + e->insns.r = get_insns (); + end_sequence (); +} + /* Update the CFG for the instructions queued on edge E. */ void diff --git a/gcc/cfgrtl.h b/gcc/cfgrtl.h index e6062d4a469c3bb9236f6ca65987f83497c58e1d..657cd08990bccb8ba77876fb885a84f159febfb1 100644 --- a/gcc/cfgrtl.h +++ b/gcc/cfgrtl.h @@ -38,6 +38,7 @@ extern edge try_redirect_by_replacing_jump (edge, basic_block, bool); extern void emit_barrier_after_bb (basic_block bb); extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx); extern void insert_insn_on_edge (rtx, edge); +extern void prepend_insn_to_edge (rtx, edge); extern void commit_one_edge_insertion (edge e); extern void commit_edge_insertions (void); extern void print_rtl_with_bb (FILE *, const rtx_insn *, dump_flags_t); diff --git a/gcc/testsuite/gcc.target/i386/pr113921.c b/gcc/testsuite/gcc.target/i386/pr113921.c new file mode 100644 index 0000000000000000000000000000000000000000..f7efba741436f1df383db618fe4292f4faa6485c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr113921.c @@ -0,0 +1,20 @@ +/* PR middle-end/113921 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +__attribute__((noipa)) long +foo (void) +{ + long v; + asm volatile goto ("jmp %l2" : "=r" (v) : "0" (27) : : lab); + return v; +lab: + return 42; +} + +int +main () +{ + if (foo () != 42) + __builtin_abort (); +}