------------------------------------- b1cs Common Subexpression Elimination ------------------------------------- Here is a small program to observe the optimization of Common Subexpression Elimination (CSE) or Full Redundancy Elimination (FRE). In the following program observe that the term "a + c" appears twice (albeit differently) and thus can be calculated once and the value is used next time when needed (the redundant calculation second time is eliminated, thus the term CSE/FRE). You must demand -O2 for CSE/FRE. Source file : b1cs.c Compilation : gcc -c -O2 -fdump-tree-all b1cs.c View result : vi -O b1cs.c.*.ssa b1cs.c.*.fre; rm -f b1cs.c.* b1cs.o Program ------- int main() { int a, b, c; b = (a + c + b) * (c + a); return b; } Questions --------- 1 How many times is the expression (a + c) computed in the original code (as seen in the SSA pass)? What about after the FRE pass? 2 Have there been any more optimizations after FRE? How will you check? 3 Why did we have to put a "return b" in this assignment? What if "return b" is changed to "return 0"? Will it make any difference?