From Optimization Compiler on Wikipedia,
Compiler optimization is generally implemented using a sequence of optimizing transformations
If you would like to study compiler optimization and are agnostic to the compiler, then take a look at the Clang/LLVM projects. Clang is a C compiler that can output LLVM IR and LLVM commands can apply specific optimization passes individually.
Output LLVM IR:
clang test.c -S -emit-llvm -o test.ll
Perform optimization pass:
opt test.ll - -S -o test_opt.ll
Compile to assembly:
llc test.ll -o test.s