Commit 524d9b4b by Pierre-Marie de Rodat Committed by Pierre-Marie de Rodat

REE: fix uninitialized registers handling

gcc/ChangeLog:

	PR rtl-optimization/66790
	* df.h (DF_MIR): New macro.
	(DF_LAST_PROBLEM_PLUS1): Update to be past DF_MIR
	(DF_MIR_INFO_BB): New macro.
	(DF_MIR_IN, DF_MIR_OUT): New macros.
	(struct df_mir_bb_info): New.
	(df_mir): New macro.
	(df_mir_add_problem, df_mir_simulate_one_insn): New forward
	declarations.
	(df_mir_get_bb_info): New.
	* df-problems.c (struct df_mir_problem_data): New.
	(df_mir_free_bb_info, df_mir_alloc, df_mir_reset,
	df_mir_bb_local_compute, df_mir_local_compute, df_mir_init,
	df_mir_confluence_0, df_mir_confluence_n,
	df_mir_transfer_function, df_mir_free, df_mir_top_dump,
	df_mir_bottom_dump, df_mir_verify_solution_start,
	df_mir_verify_solution_end): New.
	(problem_MIR): New.
	(df_mir_add_problem, df_mir_simulate_one_insn): New.
	* timevar.def (TV_DF_MIR): New.
	* ree.c: Include bitmap.h
	(add_removable_extension): Add an INIT_REGS parameter.  Use it
	to skip zero-extensions that may get an uninitialized register.
	(find_removable_extensions): Compute must-initialized registers
	using the MIR dataflow problem. Update the call to
	add_removable_extension.
	(find_and_remove_re): Call df_mir_add_problem.

gcc/testsuite/ChangeLog:

	* gnat.dg/opt50.adb: New test.
	* gnat.dg/opt50_pkg.adb: New helper.
	* gnat.dg/opt50_pkg.ads: New helper.

From-SVN: r229008
parent 32308c8d
2015-10-19 Pierre-Marie de Rodat <derodat@adacore.com>
PR rtl-optimization/66790
* df.h (DF_MIR): New macro.
(DF_LAST_PROBLEM_PLUS1): Update to be past DF_MIR
(DF_MIR_INFO_BB): New macro.
(DF_MIR_IN, DF_MIR_OUT): New macros.
(struct df_mir_bb_info): New.
(df_mir): New macro.
(df_mir_add_problem, df_mir_simulate_one_insn): New forward
declarations.
(df_mir_get_bb_info): New.
* df-problems.c (struct df_mir_problem_data): New.
(df_mir_free_bb_info, df_mir_alloc, df_mir_reset,
df_mir_bb_local_compute, df_mir_local_compute, df_mir_init,
df_mir_confluence_0, df_mir_confluence_n,
df_mir_transfer_function, df_mir_free, df_mir_top_dump,
df_mir_bottom_dump, df_mir_verify_solution_start,
df_mir_verify_solution_end): New.
(problem_MIR): New.
(df_mir_add_problem, df_mir_simulate_one_insn): New.
* timevar.def (TV_DF_MIR): New.
* ree.c: Include bitmap.h
(add_removable_extension): Add an INIT_REGS parameter. Use it
to skip zero-extensions that may get an uninitialized register.
(find_removable_extensions): Compute must-initialized registers
using the MIR dataflow problem. Update the call to
add_removable_extension.
(find_and_remove_re): Call df_mir_add_problem.
2015-10-19 Segher Boessenkool <segher@kernel.crashing.org>
* common/config/mn10300/mn10300-common.c
......@@ -51,8 +51,9 @@ union df_ref_d;
#define DF_WORD_LR 5 /* Subreg tracking lr. */
#define DF_NOTE 6 /* REG_DEAD and REG_UNUSED notes. */
#define DF_MD 7 /* Multiple Definitions. */
#define DF_MIR 8 /* Must-initialized Registers. */
#define DF_LAST_PROBLEM_PLUS1 (DF_MD + 1)
#define DF_LAST_PROBLEM_PLUS1 (DF_MIR + 1)
/* Dataflow direction. */
enum df_flow_dir
......@@ -612,12 +613,16 @@ struct df_d
#define DF_LIVE_BB_INFO(BB) (df_live_get_bb_info ((BB)->index))
#define DF_WORD_LR_BB_INFO(BB) (df_word_lr_get_bb_info ((BB)->index))
#define DF_MD_BB_INFO(BB) (df_md_get_bb_info ((BB)->index))
#define DF_MIR_BB_INFO(BB) (df_mir_get_bb_info ((BB)->index))
/* Most transformations that wish to use live register analysis will
use these macros. This info is the and of the lr and live sets. */
#define DF_LIVE_IN(BB) (&DF_LIVE_BB_INFO (BB)->in)
#define DF_LIVE_OUT(BB) (&DF_LIVE_BB_INFO (BB)->out)
#define DF_MIR_IN(BB) (&DF_MIR_BB_INFO (BB)->in)
#define DF_MIR_OUT(BB) (&DF_MIR_BB_INFO (BB)->out)
/* These macros are used by passes that are not tolerant of
uninitialized variables. This intolerance should eventually
be fixed. */
......@@ -896,6 +901,21 @@ struct df_word_lr_bb_info
bitmap_head out; /* At the bottom of the block. */
};
/* Must-initialized registers. All bitmaps are referenced by the
register number. */
struct df_mir_bb_info
{
/* Local sets to describe the basic blocks. */
bitmap_head kill; /* The set of registers unset in this block. Calls,
for instance, unset registers. */
bitmap_head gen; /* The set of registers set in this block, excluding the
ones killed later on in this block. */
/* The results of the dataflow problem. */
bitmap_head in; /* At the top of the block. */
bitmap_head out; /* At the bottom of the block. */
};
/* This is used for debugging and for the dumpers to find the latest
instance so that the df info can be added to the dumps. This
......@@ -909,6 +929,7 @@ extern struct df_d *df;
#define df_word_lr (df->problems_by_index[DF_WORD_LR])
#define df_note (df->problems_by_index[DF_NOTE])
#define df_md (df->problems_by_index[DF_MD])
#define df_mir (df->problems_by_index[DF_MIR])
/* This symbol turns on checking that each modification of the cfg has
been identified to the appropriate df routines. It is not part of
......@@ -1005,6 +1026,8 @@ extern void df_note_add_problem (void);
extern void df_md_add_problem (void);
extern void df_md_simulate_artificial_defs_at_top (basic_block, bitmap);
extern void df_md_simulate_one_insn (basic_block, rtx_insn *, bitmap);
extern void df_mir_add_problem (void);
extern void df_mir_simulate_one_insn (basic_block, rtx_insn *, bitmap, bitmap);
extern void df_simulate_find_noclobber_defs (rtx_insn *, bitmap);
extern void df_simulate_find_defs (rtx_insn *, bitmap);
extern void df_simulate_defs (rtx_insn *, bitmap);
......@@ -1111,6 +1134,15 @@ df_word_lr_get_bb_info (unsigned int index)
return NULL;
}
static inline struct df_mir_bb_info *
df_mir_get_bb_info (unsigned int index)
{
if (index < df_mir->block_info_size)
return &((struct df_mir_bb_info *) df_mir->block_info)[index];
else
return NULL;
}
/* Get the live at out set for BB no matter what problem happens to be
defined. This function is used by the register allocators who
choose different dataflow problems depending on the optimization
......
......@@ -246,6 +246,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "tree-pass.h"
#include "cgraph.h"
#include "bitmap.h"
/* This structure represents a candidate for elimination. */
......@@ -973,7 +974,8 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state)
static void
add_removable_extension (const_rtx expr, rtx_insn *insn,
vec<ext_cand> *insn_list,
unsigned *def_map)
unsigned *def_map,
bitmap init_regs)
{
enum rtx_code code;
machine_mode mode;
......@@ -993,11 +995,29 @@ add_removable_extension (const_rtx expr, rtx_insn *insn,
&& (code == SIGN_EXTEND || code == ZERO_EXTEND)
&& REG_P (XEXP (src, 0)))
{
rtx reg = XEXP (src, 0);
struct df_link *defs, *def;
ext_cand *cand;
/* First, make sure we can get all the reaching definitions. */
defs = get_defs (insn, XEXP (src, 0), NULL);
/* Zero-extension of an undefined value is partly defined (it's
completely undefined for sign-extension, though). So if there exists
a path from the entry to this zero-extension that leaves this register
uninitialized, removing the extension could change the behavior of
correct programs. So first, check it is not the case. */
if (code == ZERO_EXTEND && !bitmap_bit_p (init_regs, REGNO (reg)))
{
if (dump_file)
{
fprintf (dump_file, "Cannot eliminate extension:\n");
print_rtl_single (dump_file, insn);
fprintf (dump_file, " because it can operate on uninitialized"
" data\n");
}
return;
}
/* Second, make sure we can get all the reaching definitions. */
defs = get_defs (insn, reg, NULL);
if (!defs)
{
if (dump_file)
......@@ -1009,7 +1029,7 @@ add_removable_extension (const_rtx expr, rtx_insn *insn,
return;
}
/* Second, make sure the reaching definitions don't feed another and
/* Third, make sure the reaching definitions don't feed another and
different extension. FIXME: this obviously can be improved. */
for (def = defs; def; def = def->next)
if ((idx = def_map[INSN_UID (DF_REF_INSN (def->ref))])
......@@ -1099,18 +1119,33 @@ find_removable_extensions (void)
rtx_insn *insn;
rtx set;
unsigned *def_map = XCNEWVEC (unsigned, max_insn_uid);
bitmap_head init, kill, gen, tmp;
bitmap_initialize (&init, NULL);
bitmap_initialize (&kill, NULL);
bitmap_initialize (&gen, NULL);
bitmap_initialize (&tmp, NULL);
FOR_EACH_BB_FN (bb, cfun)
FOR_BB_INSNS (bb, insn)
{
if (!NONDEBUG_INSN_P (insn))
continue;
{
bitmap_copy (&init, DF_MIR_IN (bb));
bitmap_clear (&kill);
bitmap_clear (&gen);
set = single_set (insn);
if (set == NULL_RTX)
continue;
add_removable_extension (set, insn, &insn_list, def_map);
}
FOR_BB_INSNS (bb, insn)
{
if (NONDEBUG_INSN_P (insn))
{
set = single_set (insn);
if (set != NULL_RTX)
add_removable_extension (set, insn, &insn_list, def_map,
&init);
df_mir_simulate_one_insn (bb, insn, &kill, &gen);
bitmap_ior_and_compl (&tmp, &gen, &init, &kill);
bitmap_copy (&init, &tmp);
}
}
}
XDELETEVEC (def_map);
......@@ -1135,6 +1170,7 @@ find_and_remove_re (void)
extension instruction. */
df_set_flags (DF_RD_PRUNE_DEAD_DEFS);
df_chain_add_problem (DF_UD_CHAIN + DF_DU_CHAIN);
df_mir_add_problem ();
df_analyze ();
df_set_flags (DF_DEFER_INSN_RESCAN);
......
2015-10-19 Pierre-Marie de Rodat <derodat@adacore.com>
* gnat.dg/opt50.adb: New test.
* gnat.dg/opt50_pkg.adb: New helper.
* gnat.dg/opt50_pkg.ads: New helper.
2015-10-19 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/68019
......
-- { dg-do run }
-- { dg-options "-O3 -gnatn" }
with Opt50_Pkg; use Opt50_Pkg;
procedure Opt50 is
B : Boolean;
E : Enum;
begin
Get ("four", E, B);
if B = True then
raise Program_Error;
end if;
Get ("three", E, B);
if B = False then
raise Program_Error;
end if;
declare
A : Enum_Boolean_Array (One .. E) := (others => True);
begin
Set (A);
end;
end Opt50;
with Ada.Characters.Handling;
with Ada.Containers;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
package body Opt50_Pkg is
type Enum_Name is array (Enum) of access constant String;
Enum_Name_Table : constant Enum_Name := (
One => new String'("one"),
Two => new String'("two"),
Three => new String'("three"));
package String_To_Enum_Map is new Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => String, Element_Type => Enum,
Hash => Ada.Strings.Hash, Equivalent_Keys => "=");
function Fill_Hashed_Map return String_To_Enum_Map.Map is
Res : String_To_Enum_Map.Map;
use String_To_Enum_Map;
begin
for I in Enum_Name_Table'Range loop
declare
Kind : constant String := Enum_Name_Table (I).all;
begin
Res.Insert(Key => Kind, New_Item => I);
end;
end loop;
return Res;
end;
String_To_Enum : constant String_To_Enum_Map.Map := Fill_Hashed_Map;
procedure Get (Kind : String; Result : out Enum; Success : out Boolean) is
X : constant String := Ada.Characters.Handling.To_Lower (Kind);
use String_To_Enum_Map;
Curs : constant Cursor := String_To_Enum.Find (X);
begin
Success := Curs /= No_Element;
if Success then
Result := Element(Curs);
end if;
end;
procedure Set (A : Enum_Boolean_Array) is null;
end Opt50_Pkg;
package Opt50_Pkg is
type Enum is (One, Two, Three);
for Enum'Size use 16;
type Enum_Boolean_Array is array (Enum range <>) of Boolean;
procedure Get (Kind : String; Result : out Enum; Success : out Boolean);
procedure Set (A : Enum_Boolean_Array);
end Opt50_Pkg;
......@@ -115,6 +115,7 @@ DEFTIMEVAR (TV_DF_MD , "df multiple defs")
DEFTIMEVAR (TV_DF_RD , "df reaching defs")
DEFTIMEVAR (TV_DF_LR , "df live regs")
DEFTIMEVAR (TV_DF_LIVE , "df live&initialized regs")
DEFTIMEVAR (TV_DF_MIR , "df must-initialized regs")
DEFTIMEVAR (TV_DF_CHAIN , "df use-def / def-use chains")
DEFTIMEVAR (TV_DF_WORD_LR , "df live reg subwords")
DEFTIMEVAR (TV_DF_NOTE , "df reg dead/unused notes")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment