<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 --- - LoopVectorizer dropping inbounds from GEPs" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23997&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=U31s6NzRyjs3w3OXyZZEdvWbLCbC-QAKm7yYWRebW60&s=14c5IQsofN63HicaEKRxhS76HU_aX_Joiq5SAk-ENHU&e=">23997</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopVectorizer dropping inbounds from GEPs
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>listmail@philipreames.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I've noticed that the LoopVectorizer seems to not mark the GEPs it generates as
inbounds, even when the original GEPs being replaced are in bounds.  

Specifically, this can be reproduced with just about any vectorizable loop
which contains either a load or store to a loop variant location derived from a
pointer typed induction variable.  Consider:

define void @test2(i8* %base, i8* %end) {
entry:
  br label %loop
loop:
  %p = phi i8* [%base, %entry], [%next, %loop]
  store i8 0, i8* %p
  %next = getelementptr inbounds i8, i8* %p, i64 1
  %cmp = icmp slt i8* %p, %end
  br i1 %cmp, label %loop, label %exit
exit:
  ret void
}

The generated code for vector.body is:
vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %overflow.checked ]
  %next.gep = getelementptr i8, i8* %base, i64 %index ;;<-- KEY LINE
  %4 = bitcast i8* %next.gep to <4 x i8>*
  store <4 x i8> zeroinitializer, <4 x i8>* %4, align 1
  %index.next = add i64 %index, 4
  %5 = icmp eq i64 %index.next, %n.vec
  br i1 %5, label %middle.block, label %vector.body, !llvm.loop !5

Interestingly, using a integer induction variable for this loop and then
deriving p off of that on every iteration does end up with the new phis having
inbounds.</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>