Holooly Plus Logo

Input / Question:

Input / Question:

Use the methods of unreachable code, constant folding, reduction in strength, loop invariants, and dead code to optimize the following atom stream; you may assume that the TST condition is initially not satisfied:

(LBL, L1)

(TST, a, b,, 1, L2)

(SUB, a, 1, a)

(MUL, x, 2, b)

(ADD, x, y, z)

(ADD, 2, 3, z)

(JMP, L1)

(SUB, a, b, a)

(MUL, x, 2, z)

(LBL, L2)

Verified

Output/Answer

(LBL, L1)

(TST, a, b,, 1, L2)

(SUB, a, 1, a)

(MUL, x, 2, b)     Reduction in strength

(ADD, x, y, z)     Elimination of dead code

(ADD, 2, 3, z)     Constant folding, loop invariant

(JMP, L1)

(SUB, a, b, a)     Unreachable code

(MUL, x, 2, z)     Unreachable code

(LBL, L2)

(MOV, 5,, z)

(LBL, L1)

(TST, a, b,, 1, L2)

(SUB, a, 1, a)

(ADD, x, x, b)

(JMP, L1)

(LBL, L2)