diff --git a/gcc/testsuite/gcc.dg/torture/pr111917.c b/gcc/testsuite/gcc.dg/torture/pr111917.c
new file mode 100644
index 0000000000000000000000000000000000000000..532e30200b59ceea64c80e0fbe57de08556689c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111917.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-funswitch-loops" } */
+
+long t;
+long a() {
+  long b = t, c = t;
+  for (; b < 31; b++)
+    c <<= 1;
+  return c;
+}
+long t1;
+static
+int d() {
+  if (!t1)
+    return 0;
+e:
+f:
+  for (; a();)
+    ;
+  goto f;
+  return 0;
+}
+int main() { d(); }
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index 619b50fb4bb0d80ed62165ed87c2db110106ffdc..b4611ac82561e7c6ca6c531c8519f1f580195283 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -1455,10 +1455,7 @@ hoist_guard (class loop *loop, edge guard)
   cond_stmt = as_a <gcond *> (stmt);
   extract_true_false_edges_from_block (guard_bb, &te, &fe);
   /* Insert guard to PRE_HEADER.  */
-  if (!empty_block_p (pre_header))
-    gsi = gsi_last_bb (pre_header);
-  else
-    gsi = gsi_start_bb (pre_header);
+  gsi = gsi_last_bb (pre_header);
   /* Create copy of COND_STMT.  */
   new_cond_stmt = gimple_build_cond (gimple_cond_code (cond_stmt),
 				     gimple_cond_lhs (cond_stmt),