Hi, The issue seems to happen with -O1, because header only contains phi: <bb 3> [local count: 118111600]: # iter.12_9 = PHI <0(2), iter.12_10(10)>
and thus we hit segfault in following hunk in find_loop_guard: else { cond = dyn_cast <gcond *> (last_stmt (header)); if (! cond) return NULL; extract_true_false_edges_from_block (header, &te, &fe); since last_stmt (header) returns NULL. The attached patch, simply punts if last_stmt returns NULL, which avoids the segfault. Does it look OK ? Thanks, Prathamesh
diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index e60019db946..1439c8556ba 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -587,7 +587,10 @@ find_loop_guard (class loop *loop) next = single_succ (header); else { - cond = dyn_cast <gcond *> (last_stmt (header)); + gimple *last = last_stmt (header); + if (!last) + return NULL; + cond = dyn_cast <gcond *> (last); if (! cond) return NULL; extract_true_false_edges_from_block (header, &te, &fe);