+2015-07-08  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/66793
+       * gimple-ssa-isolate-paths.c (insert_trap_and_remove_trailing_statemen):
+       Properly split the block after stmts ending it.
+
 2015-07-08  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/66794
 
   if (walk_stmt_load_store_ops (stmt, (void *)op,
                                check_loadstore,
                                check_loadstore))
-    gsi_insert_after (si_p, seq, GSI_NEW_STMT);
+    {
+      gsi_insert_after (si_p, seq, GSI_NEW_STMT);
+      if (stmt_ends_bb_p (stmt))
+       {
+         split_block (gimple_bb (stmt), stmt);
+         return;
+       }
+    }
   else
     gsi_insert_before (si_p, seq, GSI_NEW_STMT);
 
 
+2015-07-08  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/66793
+       * gcc.dg/torture/pr66793.c: New testcase.
+
 2015-07-08  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/66794
 
--- /dev/null
+/* { dg-do link } */
+
+int a, b, c; 
+
+struct S0
+{
+  int f1;
+} *d; 
+
+void
+fn1 (struct S0 p)
+{
+  for (p.f1 = 0; p.f1 < 1; p.f1++)
+    c = a && b ? a && b : 1; 
+  for (; c;)
+    ;
+}
+
+int
+main ()
+{
+  struct S0 **f = &d;
+  d = 0; 
+  fn1 (**f); 
+  return 0;
+}