Here is Gries Method example 2.  Notice that triples sometimes are not emitted because they involve redundant expressions, and other times triples are not emitted because they compute constants and folding takes place at that step.

 

 

A = B + 3 * 2;

C = A * (B + 6);

D = 5;

A = B + (D + 1);

 

Triple

 

valnum

c

d

redundant

optimized

(1)

* 3 2

3

y

n

 

 

(2)

+ B (1)

5

n

y

 

+ B 6

(3)

= A (2)

 

 

 

 

= A (2)

(4)

+ B 6

5

n

n

(2)

 

(5)

* A (4)

6

n

y

 

* A (2)

(6)

= C (5)

 

 

 

 

= C (5)

(7)

= D 5

 

 

 

 

= D 5

(8)

+ D 1

3

y

n

(1)

 

(9)

+ B (8)

5

n

n

(2)

 

(10)

= A (9)

 

 

 

 

= A (2)

 

op

v1

v2

+

4

3

*

5

5

+

7

8

 

Avail Computations Table                Symbol Table

triple          valnum p                  A - 5 replaced by 5

(1) + 4 3          5                       B - 4

(2) * 5 5          6                       C - 6

                                                D - 7

                                                1 - 8

                                                2 - 2

                                                3 - 1

                                                5 - 7

                                                6 - 3

 

At end:

 

next i = 11

next v = 9

next p = 3

 

The constant 6, and triples (1) and (8) all have valnum = 3.  That means that triples (1) and (8) are constants in this code segment.

 

Also, the variable D and the constant 5 both have valnum = 7.  That means the variable D is a constant in this code segment.