title: How to reproduce the result of LLVM opt -O3 manually?
body: <p>I am trying to reproduce the results of applying opt -O3 to a source file in the form of LLVM IR. I want to get the same IR by manually ordering the passes used by O3 and passing them to opt. </p>
  
  <p>To illustrate what I am doing on an example, as an input I use linpack benchmark from the LLVM test suite[1]:</p>
  
  <p>1. First I produce the intermediate representation using clang:</p>
  
  <pre><code>clang -O3 -Xclang -disable-llvm-optzns -emit-llvm -S linpack-pc.c -o linpack-pc.ll
  </code></pre>
  
  <p>2. Then I use opt to optimize the IR:</p>
  
  <pre><code>opt -S -O3 -o linpack-pc-3.ll linpack-pc.ll
  </code></pre>
  
  <p>Now my goal is to produce the IR identical to linpack-pc-3.ll by passing a sequence of optimizations to opt. To get the list of optimizations used by opt for O3, I run this:</p>
  
  <pre><code>opt -O3 -disable-output -debug-pass=Arguments linpack-pc.ll
  </code></pre>
  
  <p>Which produces (shortened to avoid wasting space):</p>
  
  <pre><code>Pass Arguments:  -tti -targetlibinfo -tbaa ...
  Pass Arguments:  -targetlibinfo -tti -tbaa ...
  Pass Arguments:  -domtree
  </code></pre>
  
  <p>So apparently there are three sequences of passes applied to IR as part of O3. I wasn't able to reproduce the same IR as linpack-pc-3.ll using these passes, I tried applying passes sequentially or concatenating them and passing as a single sequence to opt. Neither produced the needed output. Moreover the performance of the final executable downgraded by about 35%. I'm using LLVM 3.8 and my OS is Ubuntu 16.04.</p>
  
  <p>[1] <a href="https://github.com/llvm/llvm-test-suite/blob/master/SingleSource/Benchmarks/Linpack/linpack-pc.c" rel="nofollow noreferrer">https://github.com/llvm/llvm-test-suite/blob/master/SingleSource/Benchmarks/Linpack/linpack-pc.c</a></p>