Index: passes.c
===================================================================
--- passes.c	(revision 191852)
+++ passes.c	(working copy)
@@ -1335,6 +1336,7 @@ init_optimization_passes (void)
           NEXT_PASS (pass_cleanup_eh);
           NEXT_PASS (pass_profile);
           NEXT_PASS (pass_local_pure_const);
+          NEXT_PASS (pass_early_ch);
 	  /* Split functions creates parts that are not run through
 	     early optimizations again.  It is thus good idea to do this
 	     late.  */
Index: tree-pass.h
===================================================================
--- tree-pass.h	(revision 191852)
+++ tree-pass.h	(working copy)
@@ -291,6 +291,7 @@ extern struct gimple_opt_pass pass_loop_
 extern struct gimple_opt_pass pass_iv_optimize;
 extern struct gimple_opt_pass pass_tree_loop_done;
 extern struct gimple_opt_pass pass_ch;
+extern struct gimple_opt_pass pass_early_ch;
 extern struct gimple_opt_pass pass_ccp;
 extern struct gimple_opt_pass pass_phi_only_cprop;
 extern struct gimple_opt_pass pass_build_ssa;
Index: tree-ssa-loop-ch.c
===================================================================
--- tree-ssa-loop-ch.c	(revision 191852)
+++ tree-ssa-loop-ch.c	(working copy)
@@ -275,3 +275,34 @@ struct gimple_opt_pass pass_ch =
     | TODO_verify_flow			/* todo_flags_finish */
  }
 };
+
+/* We duplicate loop headers early to get better profile feedback:
+   the first iteration of loop is special, because the duplicated loop header
+   test will usually pass.  */
+
+static bool
+gate_early_ch (void)
+{
+  return flag_tree_ch != 0 && (flag_branch_probabilities || profile_arc_flag);
+}
+
+struct gimple_opt_pass pass_early_ch =
+{
+ {
+  GIMPLE_PASS,
+  "early_ch",				/* name */
+  gate_early_ch,			/* gate */
+  copy_loop_headers,			/* execute */
+  NULL,					/* sub */
+  NULL,					/* next */
+  0,					/* static_pass_number */
+  TV_TREE_CH,				/* tv_id */
+  PROP_cfg | PROP_ssa,			/* properties_required */
+  0,					/* properties_provided */
+  0,					/* properties_destroyed */
+  0,					/* todo_flags_start */
+  TODO_cleanup_cfg
+    | TODO_verify_ssa
+    | TODO_verify_flow			/* todo_flags_finish */
+ }
+};
