<html>
    <head>
      <base href="https://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 --- - GVN's propagateEquality propagates wrong equality"
   href="https://llvm.org/bugs/show_bug.cgi?id=27506">27506</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN's propagateEquality propagates wrong equality
          </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>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>Scalar Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16264" name="attach_16264" title="llvm code that exposes error">attachment 16264</a> <a href="attachment.cgi?id=16264&action=edit" title="llvm code that exposes error">[details]</a></span>
llvm code that exposes error

GVN's `propagateEquality` propagates wrong equality related to icmp
instructions.

When it propagates such as "(icmp eq A B) == true", it also propagates "A ==
B". However, this may cause an incorrect behavior if either A or B is an
undefined value.

When the source code like below is given, GVN transforms the "b1" block as
shown. Suppose %x has a normal value and %u has the undef value. In the source,
"%aa" is always defined. However, in the target, "%aa" is replaced with "%u",
which is undef.

We attach an input llvm file of "opt -gvn" and a C example code that exposes
the same problem when compiled using "clang -O2". We tested this in both clang
3.7.1 and the trunk.


b0:
  %a = add i32 %x, 1
  %c = icmp eq i32 %a, %u
  br i1 %c, label %b1, label %b2

b1:
  %aa = add i32 %x, 1
  %d = call i32 @bar(i32 %aa)

->

b1:
  %d = call i32 @bar(i32 %u)</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>