diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 6859518..fe91a08 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2861,6 +2861,19 @@ swap_ops_for_binary_stmt (vec ops, } } +/* Determine if stmt A is in th next list of stmt B. */ +static inline bool +next_stmt_of (gimple a, gimple b) +{ + gimple_stmt_iterator gsi; + for (gsi = gsi_for_stmt (b); !gsi_end_p (gsi); gsi_next (&gsi)) + { + if (gsi_stmt (gsi) == a) + return true; + } + return false; +} + /* Determine if stmt A is not dominated by stmt B. If A and B are in same basic block, then A's UID has to be less than B. If they are in different BB's, then A's BB must not be dominated by B's BB. */ @@ -2871,10 +2884,13 @@ not_dominated_by (gimple a, gimple b) basic_block bb_a, bb_b; bb_a = gimple_bb (a); bb_b = gimple_bb (b); - return ((bb_a == bb_b && gimple_uid (a) < gimple_uid (b)) - || (bb_a != bb_b - && !dominated_by_p (CDI_DOMINATORS, bb_a, bb_b))); + if (bb_a != bb_b) + return !dominated_by_p (CDI_DOMINATORS, bb_a, bb_b); + if (gimple_uid (a) != 0 && gimple_uid (b) != 0) + return gimple_uid (a) < gimple_uid (b); + /* A or B is new created stmt. */ + return !next_stmt_of (a, b); } /* Among STMT1 and STMT2, return the statement that appears later. Both @@ -3085,6 +3101,7 @@ rewrite_expr_tree (gimple stmt, unsigned int opindex, gimple_assign_set_rhs2 (stmt, oe->op); update_stmt (stmt); + ensure_ops_are_available (stmt, ops, opindex); if (dump_file && (dump_flags & TDF_DETAILS)) { diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr58775.c b/gcc/testsuite/gcc.dg/tree-ssa/pr58775.c new file mode 100644 index 0000000..d3f1a1f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr58775.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void __gmpfr_vasprintf (char * t) +{ + char _4; + _Bool _5; + _Bool _6; + _Bool _7; + _Bool _9; + _Bool _10; + _Bool _11; + _Bool _12; + _Bool _13; + _Bool _14; + _Bool _15; + _Bool _16; + _Bool _17; + + _4 = *t; + _5 = _4 == 100; + _6 = _4 == 105; + _7 = _5 | _6; + _9 = _4 != 111; + _10 = !_7; + _11 = _9 & _10; + _13 = _4 != 117; + _12 = _11 & _13; + _14 = _4 != 120; + _15 = _12 & _14; + _16 = _4 != 88; + _17 = _15 & _16; + if (_17 == 0) + f (); + + return; +}