From 5e5ef52c23448a0c4c4be3f2093470c990c8c01f Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 16 Jul 2018 08:59:09 +0000 Subject: [PATCH] re PR tree-optimization/86514 (wrong manipulation of 2-dimensional packed array at -O) PR tree-optimization/86514 * tree-ssa-reassoc.c (init_range_entry) : Return for a conversion to a boolean type from a type with greater precision. From-SVN: r262684 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/opt73.adb | 34 +++++++++++++++++++++++++++++++++ gcc/tree-ssa-reassoc.c | 9 +++++++-- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/opt73.adb diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7b48f838661..5ed47c13633 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-07-16 Eric Botcazou + + PR tree-optimization/86514 + * tree-ssa-reassoc.c (init_range_entry) : Return for a + conversion to a boolean type from a type with greater precision. + 2018-07-16 Tom de Vries * var-tracking.c (vt_initialize): Print adjusted insn slim if diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9b6fe46edfa..b943f233ec0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-07-16 Eric Botcazou + + * gnat.dg/opt73.adb: New test. + 2018-07-16 Jakub Jelinek PR c++/3698 diff --git a/gcc/testsuite/gnat.dg/opt73.adb b/gcc/testsuite/gnat.dg/opt73.adb new file mode 100644 index 00000000000..38ab4774fb7 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt73.adb @@ -0,0 +1,34 @@ +-- { dg-do run } +-- { dg-options "-O" } + +procedure Opt73 is + + type Terminal_Set_Indexed_By_Non_Terminal is + array (Natural range <>, Natural range <>) of Boolean with Pack; + + type Terminal_Set_Per_Non_Terminal + (Last_Terminal : Natural; + Last_Non_Terminal : Natural) is + record + Map : Terminal_Set_Indexed_By_Non_Terminal + (1 .. Last_Non_Terminal, 0 .. Last_Terminal); + end record; + + Follow : Terminal_Set_Per_Non_Terminal (5, 4); + Expect : Terminal_Set_Per_Non_Terminal := + (5, 4, (1 => (2 => True, others => False), + others => (others => False))); + + procedure Get_Follow (Value : out Terminal_Set_Per_Non_Terminal) is + begin + Value.Map := (others => (others => False)); + Value.Map (1, 2) := True; + Value.Map (2, 0) := Value.Map (2, 0) or Value.Map (1, 0); + end; + +begin + Get_Follow (Follow); + if Follow /= Expect then + raise Program_Error; + end if; +end; diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 97a53cd27cd..41a37ab2989 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2168,8 +2168,13 @@ init_range_entry (struct range_entry *r, tree exp, gimple *stmt) continue; CASE_CONVERT: if (is_bool) - goto do_default; - if (TYPE_PRECISION (TREE_TYPE (arg0)) == 1) + { + if ((TYPE_PRECISION (exp_type) == 1 + || TREE_CODE (exp_type) == BOOLEAN_TYPE) + && TYPE_PRECISION (TREE_TYPE (arg0)) > 1) + return; + } + else if (TYPE_PRECISION (TREE_TYPE (arg0)) == 1) { if (TYPE_UNSIGNED (TREE_TYPE (arg0))) is_bool = true; -- 2.30.2