Master the fundamental concepts of optimizations through this focused micro-challenge.
CSE eliminates duplicate computations of the same expression in a basic block or extended region. LLVM's GVN pass and GCC's PRE track available expressions. If a + b appears twice with the same live operands, the second becomes a copy of the first's temp.
Track expressions computed and still valid (operands unchanged). On duplicate t2 = a + b when t1 = a + b is available, replace with t2 = t1.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement common subexpression elimination on your IR. This exercise asks you to track available expressions per block and replace redundant instructions with copies of prior results.
Implement common subexpression elimination.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github