<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 - [indvars] rewriteLoopExitValues cause run stuck"
   href="https://bugs.llvm.org/show_bug.cgi?id=50442">50442</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[indvars] rewriteLoopExitValues cause run stuck
          </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>guopeilin1@huawei.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=24882" name="attach_24882" title="A test case file">attachment 24882</a> <a href="attachment.cgi?id=24882&action=edit" title="A test case file">[details]</a></span>
A test case file

The program will run stuck when using opt -indvars test-case.ll -S.

The bug seems caused by reWriteLoopExitValues optimization. After this
optimization, the exit value ( %add.i.2. i) becomes extremely long and
complicated. Thus cost plenty of time for printing this instruction into the
screen.

And even without flag -S, I still believe that ISel will meet a segment fault
because long instruction with plenty of operands will run out the stack when
building SlectionDAG for IR.


The test-case.ll
%struct.ad = type { i8 }
%struct.ae = type { %struct.ad }
@aj = dso_local global [5 x [0 x [5 x %struct.ad]]] zeroinitializer, align 1
@al = dso_local global %struct.ae zeroinitializer, align 1

define dso_local i32 @_Z2aqv() local_unnamed_addr {
entry:
  br label %for.cond4.preheader.i

for.cond4.preheader.i:                            ; preds =
%for.cond4.preheader.i, %entry
  %av.addr.04.i = phi i32 [ 0, %entry ], [ %sub.i.2.i, %for.cond4.preheader.i ]
  %aw.sroa.0.03.i = phi i32 [ 0, %entry ], [ %dec.i, %for.cond4.preheader.i ]
  %add.i.i = add nsw i32 %av.addr.04.i, zext (i1 icmp eq (%struct.ad* bitcast
(i8* getelementptr inbounds ([5 x [0 x [5 x %struct.ad]]], [5 x [0 x [5 x
%struct.ad]]]* @aj, i64 0, i64 0, i64 9, i64 1, i32 0) to %struct.ad*),
%struct.ad* getelementptr inbounds (%struct.ae, %struct.ae* @al, i64 0, i32 0))
to i32)
  %cmp.i.i = icmp sgt i32 %av.addr.04.i, 7
  %add.i.i.op = shl i32 %add.i.i, 16
  %add.i.i.op.op = ashr i32 %add.i.i.op, 31
  %add.i.i.op.op.op = xor i32 %add.i.i.op.op, -1
  %sext.i.lobit.not = select i1 %cmp.i.i, i32 -1, i32 %add.i.i.op.op.op
  %sub.i.i = add i32 %sext.i.lobit.not, %av.addr.04.i
  %add.i.1.i = add nsw i32 %sub.i.i, zext (i1 icmp eq (%struct.ad* bitcast (i8*
getelementptr inbounds ([5 x [0 x [5 x %struct.ad]]], [5 x [0 x [5 x
%struct.ad]]]* @aj, i64 0, i64 0, i64 9, i64 1, i32 0) to %struct.ad*),
%struct.ad* getelementptr inbounds (%struct.ae, %struct.ae* @al, i64 0, i32 0))
to i32)
  %cmp.i.1.i = icmp sgt i32 %sub.i.i, 7
  %add.i.1.i.op = shl i32 %add.i.1.i, 16
  %add.i.1.i.op.op = ashr i32 %add.i.1.i.op, 31
  %add.i.1.i.op.op.op = xor i32 %add.i.1.i.op.op, -1
  %sext.1.i.lobit.not = select i1 %cmp.i.1.i, i32 -1, i32 %add.i.1.i.op.op.op
  %sub.i.1.i = add i32 %sext.1.i.lobit.not, %sub.i.i
  %add.i.2.i = add nsw i32 %sub.i.1.i, zext (i1 icmp eq (%struct.ad* bitcast
(i8* getelementptr inbounds ([5 x [0 x [5 x %struct.ad]]], [5 x [0 x [5 x
%struct.ad]]]* @aj, i64 0, i64 0, i64 9, i64 1, i32 0) to %struct.ad*),
%struct.ad* getelementptr inbounds (%struct.ae, %struct.ae* @al, i64 0, i32 0))
to i32)
  %cmp.i.2.i = icmp sgt i32 %sub.i.1.i, 7
  %add.i.2.i.op = shl i32 %add.i.2.i, 16
  %add.i.2.i.op.op = ashr i32 %add.i.2.i.op, 31
  %add.i.2.i.op.op.op = xor i32 %add.i.2.i.op.op, -1
  %sext.2.i.lobit.not = select i1 %cmp.i.2.i, i32 -1, i32 %add.i.2.i.op.op.op
  %sub.i.2.i = add i32 %sext.2.i.lobit.not, %sub.i.1.i
  %dec.i = add nsw i32 %aw.sroa.0.03.i, -1
  %cmp.i = icmp sgt i32 %aw.sroa.0.03.i, -5
  br i1 %cmp.i, label %for.cond4.preheader.i, label %_ZL2apiPiiS_.exit

_ZL2apiPiiS_.exit:                                ; preds =
%for.cond4.preheader.i
  %add.i.2.i.lcssa = phi i32 [ %add.i.2.i, %for.cond4.preheader.i ]
  %conv8.i = sext i32 %add.i.2.i.lcssa to i64
  ret i32 0
}</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>