> ping^2 > > Honza, do you think this patch can make into 4.8 stage 1?
+ if (check_value_one ^ integer_onep (val)) Probably better as != (especially because GNU coding standard allows predicates to return more than just boolean) + { + edge e1; + edge_iterator ei; + tree val = gimple_phi_arg_def (phi_stmt, i); + edge e = gimple_phi_arg_edge (phi_stmt, i); + + if (!TREE_CONSTANT (val) || !(integer_zerop (val) || integer_onep (val))) + continue; + if (check_value_one ^ integer_onep (val)) + continue; + if (VEC_length (edge, e->src->succs) != 1) + { + if (!predicted_by_p (exit_edge->src, PRED_LOOP_ITERATIONS_GUESSED) + && !predicted_by_p (exit_edge->src, PRED_LOOP_ITERATIONS) + && !predicted_by_p (exit_edge->src, PRED_LOOP_EXIT)) + predict_edge_def (e, PRED_LOOP_EXIT, NOT_TAKEN); + continue; + } + + FOR_EACH_EDGE (e1, ei, e->src->preds) + if (!predicted_by_p (exit_edge->src, PRED_LOOP_ITERATIONS_GUESSED) + && !predicted_by_p (exit_edge->src, PRED_LOOP_ITERATIONS) + && !predicted_by_p (exit_edge->src, PRED_LOOP_EXIT)) + predict_edge_def (e1, PRED_LOOP_EXIT, NOT_TAKEN); Here you found an edge that you know is going to terminate the loop and you want to predict all paths to this edge as unlikely. Perhaps you want to use predict paths leading_to_edge for edge? You do not need to check PRED_LOOP_ITERATIONS and PRED_LOOP_ITERATIONS_GUESSED because those never go to the non-exit edges. The nature of predict_paths_for_bb type heuristic is that they are not really additive: if the path leads to two different aborts it does not make it more sure that it will be unlikely. So perhaps you can add !predicted_by_p (e, pred) prior predict_edge_def call in the function? I wonder if we did VRP just before branch predction to jump thread the shortcut condtions into loopback edges, would be there still cases where this optimization will match? Honza