Master the fundamental concepts of optimizations through this focused micro-challenge.
Most execution time sits in loops. LLVM's loop vectorizer, LICM, and induction variable strength reduction target loop nests. GCC's -O3 unrolls and vectorizes inner loops. Recognizing loop headers and induction variables is the first step.
Loop-Invariant Code Motion hoists t = a + b outside the loop if a and b do not change per iteration. Strength reduction replaces i * 4 with additive induction ptr += 4.
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 loop optimizations including invariant code motion. This exercise asks you to detect loops in your CFG and hoist or rewrite computations that do not change per iteration.
Implement loop optimizations for intermediate code.
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