Factor out two optimizations into a new function. Cut, paste and rename a variable.
This is another part of the effort of enabling tail merging in the block placement. Tail merging can reverse the branch conditions even if it does not merge any tails. So, I need to optimize the conditions afterwards.
Besides above, other benefits of this patch are
- We call AnalyzeBranch() to optimize unanalyzable branches, but the result of AnalyzeBranch() is not used. Now the result is useful.
- Before the layout of all the MBBs is set, the result of AnalyzeBranch() is not correct and needs to be fixed before using it to optimize the branch conditions. Now this optimization is called after the layout, the code used to fix the result of AnalyzeBranch() is not needed.
- The branch condition of the last block is not optimized before this patch. Now it is optimized.