<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 --- - scalar/vector operations lead to division by zero"
   href="https://llvm.org/bugs/show_bug.cgi?id=27085">27085</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>scalar/vector operations lead to division by zero
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>regis.portalez@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>try to compile the following code (C) using clang 3.7 (using only mem2reg pass)

typedef unsigned char char4  __attribute__ ((vector_size (4)));

char4 f1 (char4  v)
{
  return v / 2;
}

this compiles down to (+ debug info): 

define <4 x i8> @f1(<4 x i8> %v) {
entry:
  %div = udiv <4 x i8> %v, bitcast (<1 x i32> <i32 2> to <4 x i8>)
  ret <4 x i8> %div
}

according to <a href="http://llvm.org/docs/LangRef.html#bitcast-to-instruction">http://llvm.org/docs/LangRef.html#bitcast-to-instruction</a>, bitcast
instruction does not change any bit, meaning bitcast (<1 x i32> <i32 2> to <4 x
i8>) returns <2, 0, 0, 0> as char vector. 

therefore the division in the original source code generates a division by
zero. 


I would have expected the following IL: 
define <4 x i8> @f1(<4 x i8> %v) {
entry:
  %div = udiv <4 x i8> %v, <4 x i8> <i8 2, i8 2, i8 2, i8 2>
  ret <4 x i8> %div
}</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>