Common Subexpression Elimination - Code optimization Technique in Compiler Design Last Updated : 03 Dec, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Code Optimization Technique is an approach to enhance the performance of the code by either eliminating or rearranging the code lines. Code Optimization techniques are as follows: Compile-time evaluation Common Sub-expression elimination Dead code elimination Code movement Strength reductionCommon Sub-expression Elimination:The expression or sub-expression that has been appeared and computed before and appears again during the computation of the code is the common sub-expression. Elimination of that sub-expression is known as Common sub-expression elimination. The advantage of this elimination method is to make the computation faster and better by avoiding the re-computation of the expression. In addition, it utilizes memory efficiently. Types of common sub-expression eliminationThe two types of elimination methods in common sub-expression elimination are: 1. Local Common Sub-expression elimination- It is used within a single basic block. Where a basic block is a simple code sequence that has no branches. 2. Global Common Sub-expression elimination- It is used for an entire procedure of common sub-expression elimination. Example 1: Before elimination - a = 10; b = a + 1 * 2; c = a + 1 * 2; //'c' has common expression as 'b' d = c + a; After elimination - a = 10; b = a + 1 * 2; d = b + a; Let's understand Example 1 with a diagram: fig.: Example 1As shown in the figure (fig.: Example 1), the result of 'd' would be similar with both expressions. So, we will eliminate one of the common subexpressions, as it helps in faster execution and efficient memory utilization. Example 2: Before elimination - x = 11; y = 11 * 24; z = x * 24; //'z' has common expression as 'y' as 'x' can be evaluated directly as done in 'y'.After elimination - y = 11 * 24; Comment More infoAdvertise with us Next Article Next use information in compiler design L lavleenagr7 Follow Improve Article Tags : Compiler Design Similar Reads Code Optimization in Compiler Design Code optimization is a crucial phase in compiler design aimed at enhancing the performance and efficiency of the executable code. By improving the quality of the generated machine code optimizations can reduce execution time, minimize resource usage, and improve overall system performance. This proc 9 min read Intermediate Code Generation in Compiler Design In the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the machine). The benefits of using mach 6 min read Peephole Optimization in Compiler Design Peephole optimization is a type of code Optimization performed on a small part of the code. It is performed on a very small set of instructions in a segment of code.The small set of instructions or small part of code on which peephole optimization is performed is known as peephole or window.It basic 2 min read Next use information in compiler design In compiler design, the next use information is a type of data flow analysis that can be used to optimize the allocation of registers in a computer's central processing unit (CPU). The goal of next use analysis is to determine which variables in a program are needed in the immediate future and shoul 6 min read Loop Optimization in Compiler Design Loop Optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capabilities. Most execution time of a scientific program is spent on loops. Loop 4 min read Common Sub Expression Elimination Common subexpression elimination (CSE) is a technique used to optimize the codes. It works by computing the value of the subexpression and assigning the value to a variable. Now, the initial common subexpression is replaced by that variable. It helps in reducing the number of repeated computations. 3 min read Like