I am testing the following with additional hunks in tree-ssa-loop-ivcanon.c.
Bootstrap / regtest running on x86_64-unknown-linux-gnu (gcc-8-branch). Richard. 2019-03-14 Richard Biener <rguent...@suse.de> PR middle-end/89572 * tree-scalar-evolution.c (get_loop_exit_condition): Use safe_dyn_cast. * tree-ssa-loop-ivcanon.c (canonicalize_loop_induction_variables): Use gimple_location_safe. * gcc.dg/torture/pr89572.c: New testcase. Index: gcc/testsuite/gcc.dg/torture/pr89572.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr89572.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr89572.c (working copy) @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-finline-functions" } */ + +int vh, it, k1; + +void +vn (void) +{ + ++vh; + if (vh == 0 && it == 0) + k1 = -k1; +} + +__attribute__ ((returns_twice)) void +ef (int *uw) +{ + while (uw != (void *) 0) + { + vn (); + *uw = 0; + } +} + +void +gu (int *uw) +{ + ef (uw); +} Index: gcc/tree-scalar-evolution.c =================================================================== --- gcc/tree-scalar-evolution.c (revision 269650) +++ gcc/tree-scalar-evolution.c (working copy) @@ -875,7 +875,7 @@ get_loop_exit_condition (const struct lo gimple *stmt; stmt = last_stmt (exit_edge->src); - if (gcond *cond_stmt = dyn_cast <gcond *> (stmt)) + if (gcond *cond_stmt = safe_dyn_cast <gcond *> (stmt)) res = cond_stmt; } Index: gcc/tree-ssa-loop-ivcanon.c =================================================================== --- gcc/tree-ssa-loop-ivcanon.c (revision 269650) +++ gcc/tree-ssa-loop-ivcanon.c (working copy) @@ -1177,7 +1177,7 @@ canonicalize_loop_induction_variables (s = niter_desc.may_be_zero && !integer_zerop (niter_desc.may_be_zero); } if (TREE_CODE (niter) == INTEGER_CST) - locus = gimple_location (last_stmt (exit->src)); + locus = gimple_location_safe (last_stmt (exit->src)); else { /* For non-constant niter fold may_be_zero into niter again. */ @@ -1204,7 +1204,7 @@ canonicalize_loop_induction_variables (s niter = find_loop_niter_by_eval (loop, &exit); if (exit) - locus = gimple_location (last_stmt (exit->src)); + locus = gimple_location_safe (last_stmt (exit->src)); if (TREE_CODE (niter) != INTEGER_CST) exit = NULL;