Title Defense
Presented by Supervised by
Copy propagation
Jahid Hasan ID: 171-15-3070
Md. Ruhul Amin ID: 171-15-1725
KM Sohan ID: 171-15-5666
Abir Hasan ID: 161-15-2630
Sadia Akter ID: 171-15-2260
Ms. Jakia Akhter
Lecturer
Dept. of CSE
Daffodil International University
Thursday 12 December 2019
Presented To
Title Defense
Our content is
• What is copy propagation?
• Basic RTL Demonstration
• When Copy Propagation may be Applied
• How Copy Propagation may enable other Optimizations
Title Defense
What is copy propagation?
Title Defense
Basic RTL Demonstration
The basic idea of the copy propagation optimization is to seek out two instructions where the at least one source of the second
instruction is the destination operand of the first copy instruction. In RTL,
1. B A
2. zero or more instructions
3. C f(x1, x2, ……., B, …., xn)
In other words, the code copies the value of A into both B, and then has some instruction which depends on the value of B. If the
compiler finds such a pair of instructions, and if the compiler can prove that the intermediate instructions (2) do not modify the
values of B or A, then the compiler can transform this to the equivalent code:
1. B A
2. C f(x1, x2, ……., B, …., xn)
Since the value of A has not changed, and since B also held that value, the third instruction must compute the same value.
Title Defense
When Copy Propagation may be Applied
In the earlier RTL listings, it was assumed that the instructions take place within a basic block that is, that there were no branching
instructions or function calls. However, the presence of branches or calls does not necessarily prevent the compiler from performing
this instruction. It does require that the compiler perform control flow analysis to verify a few characteristics.
First, it must be verified that the basic block which contains the assignment of B dominates the block which contains the use of B,
or in other words that the definition is always executed at least once before the use. This test prevents cases such as this conditional
statement, expressed in pseudocode:
1. if( some condition )
2. Then
3. B A
4. else
5. B X
6. end if
7. C B
Title Defense
In this example, the assignment B A does not dominate the use C B, because there is a path of execution which contains the
second assignment, but not the first (namely, the else clause). Next, it must be shown that no other assignment to A or B
dominates the second assignment and post-dominates the first assignment. In other words, the assignment B A must always
be the most recent assignment to A or B before the assignment C B. Take for example, this loop:
1. B A
2. while( some condition )
3. C B
4. A X
5. end loop
In this example, the assignment B A clearly dominates the assignment C B . However, we cannot change the second
assignment to C A.
Title Defense
How Copy Propagation may enable other Optimizations
Creation of Dead Code
Copy propagation may aid the optimization process by creating more dead code, which can later be removed by dead code
elimination. For instance,
1. B A
2. C B
3. D B
After copy propagation has been applied twice, we have
1. B A
2. C A
3. D A
Suppose that instruction (3) was the only use of memory location C. If so, then no instructions depend on the value of C, and the
instruction may be removed.
Title Defense
Constant Folding
Copy propagation may also aid constant in constant folding. If, for instance, the operand A was a constant, and the use was an
addition:
1. B 4
2. C 2+B
A single copy propagation will yield,
1. B 4
2. C 2+4
The constant can later be folded to,
1. B 4
2. C 6
Title Defense

Copy propagation

  • 1.
    Title Defense Presented bySupervised by Copy propagation Jahid Hasan ID: 171-15-3070 Md. Ruhul Amin ID: 171-15-1725 KM Sohan ID: 171-15-5666 Abir Hasan ID: 161-15-2630 Sadia Akter ID: 171-15-2260 Ms. Jakia Akhter Lecturer Dept. of CSE Daffodil International University Thursday 12 December 2019 Presented To
  • 2.
    Title Defense Our contentis • What is copy propagation? • Basic RTL Demonstration • When Copy Propagation may be Applied • How Copy Propagation may enable other Optimizations
  • 3.
    Title Defense What iscopy propagation?
  • 4.
    Title Defense Basic RTLDemonstration The basic idea of the copy propagation optimization is to seek out two instructions where the at least one source of the second instruction is the destination operand of the first copy instruction. In RTL, 1. B A 2. zero or more instructions 3. C f(x1, x2, ……., B, …., xn) In other words, the code copies the value of A into both B, and then has some instruction which depends on the value of B. If the compiler finds such a pair of instructions, and if the compiler can prove that the intermediate instructions (2) do not modify the values of B or A, then the compiler can transform this to the equivalent code: 1. B A 2. C f(x1, x2, ……., B, …., xn) Since the value of A has not changed, and since B also held that value, the third instruction must compute the same value.
  • 5.
    Title Defense When CopyPropagation may be Applied In the earlier RTL listings, it was assumed that the instructions take place within a basic block that is, that there were no branching instructions or function calls. However, the presence of branches or calls does not necessarily prevent the compiler from performing this instruction. It does require that the compiler perform control flow analysis to verify a few characteristics. First, it must be verified that the basic block which contains the assignment of B dominates the block which contains the use of B, or in other words that the definition is always executed at least once before the use. This test prevents cases such as this conditional statement, expressed in pseudocode: 1. if( some condition ) 2. Then 3. B A 4. else 5. B X 6. end if 7. C B
  • 6.
    Title Defense In thisexample, the assignment B A does not dominate the use C B, because there is a path of execution which contains the second assignment, but not the first (namely, the else clause). Next, it must be shown that no other assignment to A or B dominates the second assignment and post-dominates the first assignment. In other words, the assignment B A must always be the most recent assignment to A or B before the assignment C B. Take for example, this loop: 1. B A 2. while( some condition ) 3. C B 4. A X 5. end loop In this example, the assignment B A clearly dominates the assignment C B . However, we cannot change the second assignment to C A.
  • 7.
    Title Defense How CopyPropagation may enable other Optimizations Creation of Dead Code Copy propagation may aid the optimization process by creating more dead code, which can later be removed by dead code elimination. For instance, 1. B A 2. C B 3. D B After copy propagation has been applied twice, we have 1. B A 2. C A 3. D A Suppose that instruction (3) was the only use of memory location C. If so, then no instructions depend on the value of C, and the instruction may be removed.
  • 8.
    Title Defense Constant Folding Copypropagation may also aid constant in constant folding. If, for instance, the operand A was a constant, and the use was an addition: 1. B 4 2. C 2+B A single copy propagation will yield, 1. B 4 2. C 2+4 The constant can later be folded to, 1. B 4 2. C 6
  • 9.