**
Revision
366665
by skatkov:
**[Loop Peeling] Fix the handling of branch weights of peeled off branches.

Current algorithm to update branch weights of latch block and its copies is

based on the assumption that number of peeling iterations is approximately equal

to trip count.

However it is not correct. According to profitability check in one case we can decide to peel

in case it helps to reduce the number of phi nodes. In this case the number of peeled iteration

can be less then estimated trip count.

This patch introduces another way to set the branch weights to peeled of branches.

Let F is a weight of the edge from latch to header.

Let E is a weight of the edge from latch to exit.

F/(F+E) is a probability to go to loop and E/(F+E) is a probability to go to exit.

Then, Estimated TripCount = F / E.

For I-th (counting from 0) peeled off iteration we set the the weights for

the peeled latch as (TC - I, 1). It gives us reasonable distribution,

The probability to go to exit 1/(TC-I) increases. At the same time

the estimated trip count of remaining loop reduces by I.

As a result after peeling off N iteration the weights will be

(F - N * E, E) and trip count of loop becomes

F / E - N or TC - N.

The idea is taken from the review of the patch D63918 proposed by Philip.

Reviewers: reames, mkuper, iajbar, fhahn

Reviewed By: reames

Subscribers: hiraditya, zzheng, llvm-commits

Differential Revision: https://reviews.llvm.org/D64235