<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 - Miscompile by -loop-bound-split (load from wrong address after split)"
   href="https://bugs.llvm.org/show_bug.cgi?id=51866">51866</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Miscompile by -loop-bound-split (load from wrong address after split)
          </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>enhancement
          </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>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25259" name="attach_25259" title="bbi-60288.ll reproducer">attachment 25259</a> <a href="attachment.cgi?id=25259&action=edit" title="bbi-60288.ll reproducer">[details]</a></span>
bbi-60288.ll reproducer

llvm commit: 0dc461441eed

Reproduce with:
 opt -passes='module(loop-bound-split)' -S -o - bbi-60288.ll

In the input the loop executes 10 rounds, and for each round we read in B with
the induction variable "i" as offset.

After loop-bound-split, the loop is split in two, one for i < 5 and one for
larger i. However, in the second loop we starts over reading at offset 0 in B
instead of offset 5.

I.e. in the second loop we do

for.cond.split:                                   ; preds =
%for.cond.split.preheader, %for.inc.split
  %i.0.split = phi i16 [ %inc.split, %for.inc.split ], [ 0,
%for.cond.split.preheader ]
  %exitcond.not.split = icmp eq i16 %i.0.split, 10
  br i1 %exitcond.not.split, label %for.end.loopexit, label %for.body.split

for.body.split:                                   ; preds = %for.cond.split
  %cmp1.split = icmp ult i16 %i.0.split, 5
  %arrayidx.split = getelementptr inbounds [10 x i16], [10 x i16]* @B, i16 0,
i16 %i.0.split
  %2 = load i16, i16* %arrayidx.split, align 1
  br i1 false, label %if.then.split, label %if.else.split

where %i.0.split "starts over" from 0 in the PHI and %i.0.split is used in the
gep determining where to read.
I think the PHI should be

  %i.0.split = phi i16 [ %inc.split, %for.inc.split ], [ 5,
%for.cond.split.preheader ]

instead.</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>