Branch Elimination via Multi-variable Condition Merging
Conditional branches are expensive. Branches require a significant percentage of execution cycles since they occur frequently and cause pipeline flushes when mispredicted. In addition, branches result in forks in the control flow, which can prevent other code-improving transformations from being applied. In this paper we describe profile-based techniques for replacing the execution of a set of two or more branches with a single branch on a conventional scalar processor. First, we gather profile information to detect the frequently executed paths in a program. Second, we detect sets of conditions in frequently executed paths that can be merged into a single condition. Third, we estimate the benefit of merging each set of conditions. Finally, we restructure the control flow to merge the sets that are deemed beneficial. The results show that eliminating branches by merging conditions can significantly reduce the number of conditional branches performed in non-numerical applications.
KeywordsMultiple Variable Single Branch Conditional Branch Execution Cycle Branch Prediction
Unable to display preview. Download preview PDF.
- 2.Allen, F.E., Cocke, J.: A catalogue of optimizing transformations. In: Rustin, R., ed.: Design and Optimization of Compilers, pp. 1–30. Prentice-Hall, Englewood Cliffs (1971); TransformationsGoogle Scholar
- 3.Granlund, T., Kenner, R.: Eliminating branches using a superoptimiser and the GNU C compiler. In: Fraser, C.W. (ed.) Proceedings of the SIGPLAN 1992 Conference on Programming Language Design and Implementation, San Francisco, CA, pp. 341–352. ACM Press, New York (1992)Google Scholar
- 6.Uh, G.R., Whalley, D.B.: Coalescing conditional branches into efficient indirect jumps. In: Proceedings of the International Static Analysis Symposium, pp. 315–329 (1997)Google Scholar
- 7.Yang, M., Uh, G.R., Whalley, D.B.: Improving performance by branch reordering. In: Proceedings of the SIGPLAN 1998 Conference on Programming Language Design and Implementation, Montreal, Canada, pp. 130–141. ACM Press, New York (1998)Google Scholar
- 8.Yang, M., Uh, G.R., Whalley, D.B.: Efficient and effective branch reordering using profile data, vol. 24, pp. 667–697 (2002)Google Scholar
- 9.Hennessy, J., Patterson, D.: Computer Architecture: A Quantitative Approach, 2nd edn. Morgan Kaufmann Publishers Inc., San Francisco (1996)Google Scholar
- 10.Warter, N.J., Mahlke, S.A., Hwu, W.M.W., Rau, B.R.: Reverse If-Conversion. In: Proceedings of the Conference on Programming Language Design and Implementation, pp. 290–299 (1993)Google Scholar
- 11.Schlansker, M., Kathail, V.: Critical path reduction for scalar programs. In: proceedings of the 28th Annual International Symposium on Microarchitecture, Ann Arbor, Michigan, IEEE Computer Society TC-MICRO and ACM SIGMICRO, pp. 57–69. IEEE Computer Society Press, Los Alamitos (1995)Google Scholar
- 13.Kreahling, W., Whalley, D., Bailey, M., Yuan, X., Uh, G.R., van Engelen, R.: Branch elimination by condition merging. Technical report, Florida State University (2003), http://websrv.cs.fsu.edu/research/reports/TR-030201.ps