
The Linux kernel and the following testcase distilled from it is miscompiled, because tree-outof-ssa.cc (eliminate_phi) emits some fixups on some of the edges (but doesn't commit edge insertions). Later expand_asm_stmt emits further instructions on the same edge. Now the problem is that expand_asm_stmt uses insert_insn_on_edge to add its own fixups, but that function appends to the existing sequence on the edge if any. And the bug triggers when the fixup sequence emitted by eliminate_phi uses a pseudo which the fixup sequence emitted by expand_asm_stmt later on sets. So, we end up with (set (reg A) (asm_operands ...)) and on one of the edges queued sequence (set (reg C) (reg B)) // added by eliminate_phi (set (reg B) (reg A)) // added by expand_asm_stmt That is wrong, what we emit by expand_asm_stmt needs to be as close to the asm_operands as possible (they aren't known until expand_asm_stmt is called, the PHI fixup code assumes it is reg B which holds the right value) and the PHI adjustments need to be done after it. So, the following patch introduces a prepend_insn_to_edge function and uses it from expand_asm_stmt, so that we queue (set (reg B) (reg A)) // added by expand_asm_stmt (set (reg C) (reg B)) // added by eliminate_phi instead and so the value from the asm_operands output propagates correctly to the PHI result. 2024-02-15 Jakub Jelinek <jakub@redhat.com> PR middle-end/113921 * cfgrtl.h (prepend_insn_to_edge): New declaration. * cfgrtl.cc (insert_insn_on_edge): Clarify behavior in function comment. (prepend_insn_to_edge): New function. * cfgexpand.cc (expand_asm_stmt): Use prepend_insn_to_edge instead of insert_insn_on_edge. * gcc.target/i386/pr113921.c: New test.
62 lines
2.6 KiB
C++
62 lines
2.6 KiB
C++
/* Define control flow data structures for the CFG.
|
|
Copyright (C) 2014-2024 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GCC_CFGRTL_H
|
|
#define GCC_CFGRTL_H
|
|
|
|
extern void delete_insn (rtx_insn *);
|
|
extern bool delete_insn_and_edges (rtx_insn *);
|
|
extern void delete_insn_chain (rtx, rtx_insn *, bool);
|
|
extern basic_block create_basic_block_structure (rtx_insn *, rtx_insn *,
|
|
rtx_note *, basic_block);
|
|
extern void compute_bb_for_insn (void);
|
|
extern void free_bb_for_insn (void);
|
|
extern rtx_insn *entry_of_function (void);
|
|
extern void update_bb_for_insn (basic_block);
|
|
extern bool contains_no_active_insn_p (const_basic_block);
|
|
extern bool forwarder_block_p (const_basic_block);
|
|
extern bool can_fallthru (basic_block, basic_block);
|
|
extern rtx_note *bb_note (basic_block);
|
|
extern rtx_code_label *block_label (basic_block);
|
|
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);
|
|
extern void update_br_prob_note (basic_block);
|
|
extern rtx_insn *get_last_bb_insn (basic_block);
|
|
extern void fixup_partitions (void);
|
|
extern bool purge_dead_edges (basic_block);
|
|
extern bool purge_all_dead_edges (void);
|
|
extern bool fixup_abnormal_edges (void);
|
|
extern void update_cfg_for_uncondjump (rtx_insn *);
|
|
extern rtx_insn *unlink_insn_chain (rtx_insn *, rtx_insn *);
|
|
extern void relink_block_chain (bool);
|
|
extern rtx_insn *duplicate_insn_chain (rtx_insn *, rtx_insn *,
|
|
class loop *, class copy_bb_data *);
|
|
extern void cfg_layout_initialize (int);
|
|
extern void cfg_layout_finalize (void);
|
|
extern void break_superblocks (void);
|
|
extern void init_rtl_bb_info (basic_block);
|
|
extern void find_bbs_reachable_by_hot_paths (hash_set <basic_block> *);
|
|
|
|
#endif /* GCC_CFGRTL_H */
|