<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Bad O2,O3 optimization in some cases"
   href="http://llvm.org/bugs/show_bug.cgi?id=19157">19157</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bad O2,O3 optimization in some cases
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kostya27@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have two almost similar programs 1.bc and 2.bc which generated by crystal:
<a href="https://gist.github.com/kostya/c1748e5dde4aefa4cb14">https://gist.github.com/kostya/c1748e5dde4aefa4cb14</a>

and perfomance for both should be the same, but:

/usr/lib/llvm-3.3/bin/opt 1.bc -o 1.obc -O3 && /usr/lib/llvm-3.3/bin/llc 1.obc
-o 1.s && gcc -c 1.s -o 1.o && gcc  1.o -o 1 -lm -lpcre -lgc -lrt -lunwind &&
./1
1.42804

/usr/lib/llvm-3.3/bin/opt 2.bc -o 2.obc -O3 && /usr/lib/llvm-3.3/bin/llc 2.obc
-o 2.s && gcc -c 2.s -o 2.o && gcc  2.o -o 2 -lm -lpcre -lgc -lrt -lunwind &&
./2
0.321645

1.bc 4.4 times slower than 2.bc with O3.

But if i add: -scalarrepl -instcombine, it became the same:

/usr/lib/llvm-3.3/bin/opt 1.bc -o 1.obc -O3 -scalarrepl -instcombine &&
/usr/lib/llvm-3.3/bin/llc 1.obc -o 1.s && gcc -c 1.s -o 1.o && gcc  1.o -o 1
-lm -lpcre -lgc -lrt -lunwind && ./1
0.310694

/usr/lib/llvm-3.3/bin/opt 2.bc -o 2.obc -O3 -scalarrepl -instcombine &&
/usr/lib/llvm-3.3/bin/llc 2.obc -o 2.s && gcc -c 2.s -o 2.o && gcc  2.o -o 2
-lm -lpcre -lgc -lrt -lunwind && ./2
0.317292</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>