Abstract
Detection of redundant expressions in a program based on values is a well researched problem done with a view to eliminate the redundancies so as to improve the run-time efficiency of the program. The problem entails the detection of equivalent expressions in a program. Here we present an iterative data-flow analysis algorithm to detect equivalent expressions in SSA for the purpose of detection of redundancies. The central challenge in this static analysis is to define a “join” operation to detect all equivalences at a join point such that any later occurrences of redundant expressions are detected in polynomial time. We achieve this by introducing the notion of value \(\phi \) -function. We claim the algorithm is complete and takes only polynomial time. We implemented the algorithm in LLVM and demonstrated its performance.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
A copy statement is an assignment statement of the form \(x = y\), where y is a variable.
- 2.
In the literature, a \(\phi \)-function restricts its operands to different subscripted versions of the same non-SSA variable, say \(\phi (x_{1}, x_{2})\).
- 3.
Point p in a CFG dominates point \(p^{\prime }\) if all paths from entry point to \(p^{\prime }\) go through p.
- 4.
Merge of expressions can be viewed as an extended notion of merge of variables. “Merge of expressions” \(e_{i1}+e_{i2}\) and \(e_{j1}+e_{j2}\) is the expression \(e_{i}+e_{j}\) such that \(e_{i}\) is the merge of \(e_{i1}\) and \(e_{j1}\). Similarly, \(e_{j}\) is the merge of \(e_{i2}\) and \(e_{j2}\).
- 5.
Since \(x_{3}\) is a merge of variables \(x_{1}\) and \(x_{2}\), expression \(x_{3}+1\) is a merge of \(x_{1}+1\) and \(x_{2}+1\).
- 6.
Transfer function for a block is the composition of transfer function of each statement in the block [1].
References
Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques, and Tools, 2nd edn. Addison Wesley, Boston (2006)
Alpern, B., Wegman, M.N., Zadeck, F.K.: Detecting equality of variables in programs. In: Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1988, pp. 1–11. ACM, New York (1988)
Briggs, P., Cooper, K., Simpson, L.: Value numbering. Software: Practice and Experience 27(6), 701–724 (1997)
Gulwani, S., Necula, G.C.: A polynomial-time algorithm for global value numbering. In: Giacobazzi, R. (ed.) SAS 2004. LNCS, vol. 3148, pp. 212–227. Springer, Heidelberg (2004)
Kildall, G.A.: A unified approach to global program optimization. In: Proceedings of the 1st Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL 1973, pp. 194–206. ACM, New York (1973)
Nie, J.-T., Cheng, X.: An efficient SSA-based algorithm for complete global value numbering. In: Shao, Z. (ed.) APLAS 2007. LNCS, vol. 4807, pp. 319–334. Springer, Heidelberg (2007)
Odaira, R., Hiraki, K.: Partial value number redundancy elimination. In: Eigenmann, R., Li, Z., Midkiff, S.P. (eds.) LCPC 2004. LNCS, vol. 3602, pp. 409–423. Springer, Heidelberg (2005)
Rüthing, O., Knoop, J., Steffen, B.: Detecting equalities of variables: combining efficiency with precision. In: Cortesi, A., Filé, G. (eds.) SAS 1999. LNCS, vol. 1694, pp. 232–247. Springer, Heidelberg (1999)
Saleena, N., Paleri, V.: Global value numbering for redundancy detection: a simple and efficient algorithm. In: Proceedings of the 29th Annual ACM Symposium on Applied Computing, SAC 2014, pp. 1609–1611. ACM, New York (2014)
Simpson, L.T.: Value-driven redundancy elimination. Ph.D. thesis, Rice University, Houston, TX, USA (1996)
VanDrunen, T., Hosking, A.L.: Value-based partial redundancy elimination. In: Duesterwald, E. (ed.) CC 2004. LNCS, vol. 2985, pp. 167–184. Springer, Heidelberg (2004)
Acknowledgements
We thank Vineeth Paleri, Muralikrishnan K, Vinith R, and the anonymous reviewers for their insightful comments.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Appendix
A Appendix
1.1 A.1 VALUEPHIFUNC
This recursive function computes value \(\phi \)-function of a given value expression. The function assumes partitions at out of each block is available to it. The function uses equiVE to replace operands of a given value expression with equivalent value \(\phi \)-functions, whenever possible. Else it returns the value expression as such. The getVN function used here takes a partition at out of either the left or right predecessor of a join block k. It searches for the input value expression in the partition and returns its value number, if present. If the partition was searched for previously then the function returns a new value number. This case can arise with loops in the program.
1.2 A.2 Proof
Correctness of Join Algorithm
Lemma 1
If \(e_{1} \equiv e_{2}\) at a point p and the point p dominates join point j then \(e_{1} \equiv e_{2}\) at j iff the algorithm detects their equivalence.
Proof
Let expressions \(e_{1}\) and \(e_{2}\) be equivalent at a point p such that p dominates join point j. Since a variable is defined only once in SSA the expressions are equivalent in each path to j. Line 1 in the algorithm Intersect ensures such common equivalences are detected at the join point. \(\square \)
Lemma 2
If variable \(x \equiv y\) in each path to join point j then \(x \equiv y\) at j iff the algorithm detects their equivalence.
Proof
Let two variables x and y be equivalent in each path to join point j. Then by suitably transforming the \(\phi \)-functions in the join block j and by line 1 of the Intersect algorithm such equivalences could also be detected. \(\square \)
Let there be expressions \(e_{i}\) in each path to an expression e and \(e_{i} \equiv e\) in respective paths. The equivalences are detected by the transferFunction algorithm which is proved below.
Correctness of transferFunction Algorithm
Lemma 3
Let \(x = e\) be a statement at a point p in the program and there exist expressions \(e_{i}\) at points \(p_{i}\) in each path to p such that at least one of the \(p_{i}\)’s does not dominate p. Then expression e has a value \(\phi \)-function, as computed by valuePhiFunc algorithm, iff expressions \(e_{i}\) and e are equivalent in respective paths.
Proof
This can be proved by induction on the number of join points in paths with the base case similar to that in Fig. 4. \(\square \)
Lemma 4
Let \(x = e\) be a statement at a point p in the program and there exists expressions \(e_{i}\) in each path to p. Expressions \(e_{i}\) and e are equivalent in respective paths iff the transferFunction algorithm detects the equivalences.
Proof
Let the expression(s) \(e_{i}\) appear at point \(p^{\prime }\) such that \(p^{\prime }\) dominate p. Then an equivalence class for \(e_{i}\) with its value expression will appear in the partition at \(p^{\prime }\) (ensured by lines 7 and 8 in the algorithm). Since a variable is defined only once in SSA the partition at in point of the statement \(x = e\) will have a class with the value expression of \(e_{i}\). Then line 6 in the algorithm ensures equivalence of \(e_{i}\) and e is detected.
Now consider the case where an expression \(e_{i}\) appear at a point \(p^{\prime }\) such that \(p^{\prime }\) does not dominate p. In this case computation of value \(\phi \)-function in line 5 (Lemma 3) and subsequent check for its existence in line 6 ensures detection of equivalences of \(e_{i}\) and e in respective paths. \(\square \)
Correctness of Iterative Data-Flow Analysis Algorithm
Theorem 1
(Soundness and Completeness). Let P be a partition at a point p computed by the iterative data-flow analysis algorithm. Two expressions are equivalent at p iff the algorithm detects their equivalence.
Proof
This follows from Lemmas 1, 2, and 4. \(\square \)
Correctness of Algorithm for Detection of Redundancies
Theorem 2
(Soundness and Completeness). Let \(s: z = x + y\) be a statement at a point p. The expression \(x+y\) is redundant iff the algorithm detects its redundancy.
Proof
This follows from Theorem 1. \(\square \)
Rights and permissions
Copyright information
© 2015 Springer International Publishing Switzerland
About this paper
Cite this paper
Pai, R.R. (2015). Detection of Redundant Expressions: A Complete and Polynomial-Time Algorithm in SSA. In: Feng, X., Park, S. (eds) Programming Languages and Systems. APLAS 2015. Lecture Notes in Computer Science(), vol 9458. Springer, Cham. https://doi.org/10.1007/978-3-319-26529-2_4
Download citation
DOI: https://doi.org/10.1007/978-3-319-26529-2_4
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-26528-5
Online ISBN: 978-3-319-26529-2
eBook Packages: Computer ScienceComputer Science (R0)