For a theoretical study I have implemented Meet over all path for constant propagation. Since the lattice of constant propagation is non distributive, it is expected that Maximum Fixed Point calculation and Meet Over all Path may give different results. Can anyone give such an example program.
Q2 : Also is there a program in which sparse conditional constant propagation pass(-sccp) in llvm will fail to detect a constant.
An example taken from here:
if (...)
x = 1;
else
x = -1;
y = x * x;
With the constant propagation method, the value of x
is not a constant after the if-statement. Thus, the value of y
is not a constant. Formally, if F
is a function for the last statement, we have F(1 ⨆ -1) = F(⊤) = ⊤
.
With MOP, the value of y
is a join from two possible paths, and therefore is known to be 1
. Formally, F(1) ⨆ F(-1) = 1 ⨆ 1 = 1
.