<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 --- - InstCombine can't fold "select %c, undef, %foo" to %foo (miscompile)"
   href="https://llvm.org/bugs/show_bug.cgi?id=31633">31633</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine can't fold "select %c, undef, %foo" to %foo  (miscompile)
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>miscompilation
          </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>nunoplopes@sapo.pt
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>david.majnemer@gmail.com, gil.hur@sf.snu.ac.kr, juneyoung.lee@sf.snu.ac.kr, llvm-bugs@lists.llvm.org, regehr@cs.utah.edu, sanjoy@playingwithpointers.com, spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>InstCombine currently folds  "select %c, undef, %foo" into %foo, because it
assumes that undef can take any value that %foo may take.
This is not correct since %foo may be poison.
This problem has long been know, but I'm adding now an end-to-end
miscompilation example triggered by this bug.

$ cat select-undef.ll
define i1 @f(i1 %c, i32 %y) {
  %y2 = add nsw i32 %y, 1
  %s = select i1 %c, i32 undef, i32 %y2
  %r = icmp sgt i32 %s, %y
  ret i1 %r
}

$ opt -S select-undef.ll -instcombine
define i1 @f(i1 %c, i32 %y) {
  ret i1 true
}

Which is wrong for the case %y=0x7FFFFFFF and %c=true. %y2 overflows and
becomes poison, but the select should return undef only, not poison.
Alive report: <a href="http://rise4fun.com/Alive/XGW">http://rise4fun.com/Alive/XGW</a>

Related with PR31632.</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>