<html>
    <head>
      <base href="https://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 - extractelement lowering and LangRef don't match"
   href="https://bugs.llvm.org/show_bug.cgi?id=50382">50382</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>extractelement lowering and LangRef don't match
          </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>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Target Description Classes
          </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>florian_hahn@apple.com, fwage73@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, regehr@cs.utah.edu, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LangRef says that extractelement with an OOB index yields poison.
However, it seems all targets lower an OOB index operation to a crash:
<a href="https://gcc.godbolt.org/z/9jxd9esnE">https://gcc.godbolt.org/z/9jxd9esnE</a>
This lowering would correspond to an UB semantics rather than poison on OOB.

define i32 @f(<4 x i32>* %x, i64 %idx) {
  %lv = load <4 x i32>, <4 x i32>* %x
  %r = extractelement <4 x i32> %lv, i64 %idx
  ret i32 %r
}

x86:
    mov     eax, dword ptr [rdi + 4*rsi]
    ret


We have 2 options:
 1) Change LangRef so that extractelement gives UB on OOB index
 2) Mask the index when lowering (unless it's known to be inbounds)

I don't know what the implications of 1) are. i.e., which front-ends produce it
and from which code and which guarantees those front-ends need.</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>