From 86c8eea6689cb62d8aeff6e4649fae158015981e Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 2 Aug 2018 13:19:50 +0000 Subject: [PATCH] re PR tree-optimization/86816 (ICE: SIGSEGV in tree-ssa-pre / tail_merge_optimize) 2018-08-02 Richard Biener PR tree-optimization/86816 * tree-ssa-tail-merge.c (tail_merge_valueize): New function which checks for value availability before querying it. (gvn_uses_equal): Use it. (same_succ_hash): Likewise. (gimple_equal_p): Likewise. * g++.dg/torture/pr86816.C: New testcase. From-SVN: r263257 --- gcc/ChangeLog | 9 ++++++ gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.dg/torture/pr86816.C | 42 ++++++++++++++++++++++++++ gcc/tree-ssa-tail-merge.c | 21 +++++++++++-- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr86816.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2a506ee5ffd..e62b9efb2ed 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2018-08-02 Richard Biener + + PR tree-optimization/86816 + * tree-ssa-tail-merge.c (tail_merge_valueize): New function + which checks for value availability before querying it. + (gvn_uses_equal): Use it. + (same_succ_hash): Likewise. + (gimple_equal_p): Likewise. + 2018-08-02 Nick Clifton PR target/86789 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cd413d3b02e..b0e7505500d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-02 Richard Biener + + PR tree-optimization/86816 + * g++.dg/torture/pr86816.C: New testcase. + 2018-08-02 Richard Sandiford * gcc.target/aarch64/f16_mov_immediate_1.c: Expect fmov immediate diff --git a/gcc/testsuite/g++.dg/torture/pr86816.C b/gcc/testsuite/g++.dg/torture/pr86816.C new file mode 100644 index 00000000000..604a7d48cd1 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr86816.C @@ -0,0 +1,42 @@ +// { dg-do compile } + +class Signal +{ +public: + int m_Mode; +}; + +class Ctx +{ +public: + bool m_Invert; + + void DoSomething(); +}; + +class Test +{ + void TestIce( Ctx& ctx, Signal* sig); +}; + +void Test::TestIce( Ctx& ctx, Signal* sig) +{ + int invert = false; + + if( ! ctx.m_Invert) + invert = ! invert; + + switch( sig->m_Mode) + { + case 1: + invert = ! invert; + break; + + case 2: + invert = true; + break; + } + + if( invert) + ctx.DoSomething(); +} diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c index 15838816d86..837679a6370 100644 --- a/gcc/tree-ssa-tail-merge.c +++ b/gcc/tree-ssa-tail-merge.c @@ -286,6 +286,21 @@ struct aux_bb_info #define BB_VOP_AT_EXIT(bb) (((struct aux_bb_info *)bb->aux)->vop_at_exit) #define BB_DEP_BB(bb) (((struct aux_bb_info *)bb->aux)->dep_bb) +/* Valueization helper querying the VN lattice. */ + +static tree +tail_merge_valueize (tree name) +{ + if (TREE_CODE (name) == SSA_NAME + && has_VN_INFO (name)) + { + tree tem = VN_INFO (name)->valnum; + if (tem != VN_TOP) + return tem; + } + return name; +} + /* Returns true if the only effect a statement STMT has, is to define locally used SSA_NAMEs. */ @@ -371,7 +386,7 @@ gvn_uses_equal (tree val1, tree val2) if (val1 == val2) return true; - if (vn_valueize (val1) != vn_valueize (val2)) + if (tail_merge_valueize (val1) != tail_merge_valueize (val2)) return false; return ((TREE_CODE (val1) == SSA_NAME || CONSTANT_CLASS_P (val1)) @@ -481,7 +496,7 @@ same_succ_hash (const same_succ *e) for (i = 0; i < gimple_call_num_args (stmt); i++) { arg = gimple_call_arg (stmt, i); - arg = vn_valueize (arg); + arg = tail_merge_valueize (arg); inchash::add_expr (arg, hstate); } } @@ -1147,7 +1162,7 @@ gimple_equal_p (same_succ *same_succ, gimple *s1, gimple *s2) if (lhs1 == NULL_TREE || lhs2 == NULL_TREE) return false; if (TREE_CODE (lhs1) == SSA_NAME && TREE_CODE (lhs2) == SSA_NAME) - return vn_valueize (lhs1) == vn_valueize (lhs2); + return tail_merge_valueize (lhs1) == tail_merge_valueize (lhs2); return operand_equal_p (lhs1, lhs2, 0); case GIMPLE_ASSIGN: -- 2.30.2