<html>
    <head>
      <base href="http://bugs.llvm.org/">
    </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 - Miscompile in GVN due to bug in BasisAA"
   href="http://bugs.llvm.org/show_bug.cgi?id=32314">32314</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Miscompile in GVN due to bug in BasisAA
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Global Analyses
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>craig.topper@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18113" name="attach_18113" title="IR just before GVN runs.">attachment 18113</a> <a href="attachment.cgi?id=18113&action=edit" title="IR just before GVN runs.">[details]</a></span>
IR just before GVN runs.

In the attached IR, GVN removes the following load

  %6 = load i32, i32* %p.017, align 4, !tbaa !1

as it believes it can get the value from the previous iteration of the loop.

What it fails to realize is that this store

  store i32 50, i32* %arrayidx, align 4, !tbaa !1

aliases the load.

This is because during BasicAA we go through this PHI feeding the load

  %p.017 = phi i32* [ %r, %entry ], [ %arrayidx3, %for.body ]

to find this GEP

  %arrayidx3 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64
%indvars.iv

then compare it to this GEP which feeds the store

  %arrayidx = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 %4

Then we ask ValueTracking if %4 is known non-equal to %indvars.iv.
ValueTracking sees that %4 is equal to %indvars.iv - 1, so returns that they
are known non-equal and BasicAA returns NoAlias. But this is wrong because we
crossed a PHI to get to the GEP using %indvars.i so we're really looking at
%indvars.iv from two different loop iterations.</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>