<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 - A missed mid-end opt to remove unnecessary instrs inside the loop"
   href="https://bugs.llvm.org/show_bug.cgi?id=40706">40706</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>A missed mid-end opt to remove unnecessary instrs inside the loop
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ning.xie@huawei.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the following loop represented in llvm IR:

for.body.lr.ph:                                   ; preds = %if.end19
  %conv23 = zext i8 %conv2 to i32
  %3 = zext i8 %ucInputNum.addr.0 to i64
  %4 = shl i64 %3, 2
  br label %for.body

for.body:                                         ; preds = %for.body,
%for.body.lr.ph
  %lsr.iv = phi i64 [ %lsr.iv.next, %for.body ], [ 0, %for.body.lr.ph ]
  %ulTemp.0101 = phi i32 [ 0, %for.body.lr.ph ], [ %phitmp, %for.body ]
  ……
  %not.cmp39 = xor i1 %cmp39, true
  %cond48 = zext i1 %not.cmp39 to i32
  %add49 = add nuw nsw i32 %ulTemp.0101, %cond48
  %phitmp = and i32 %add49, 65535                        <------ A
  %lsr.iv.next = add nuw nsw i64 %lsr.iv, 4
  %tmp = trunc i64 %lsr.iv.next to i32
  %tmp106 = trunc i64 %4 to i32
  %exitcond = icmp eq i32 %tmp106, %tmp
  br i1 %exitcond, label %for.end, label %for.body

for.end:
  ……

The instruction A:  %phitmp = and i32 %add49, 65535 is redundant and can be
removed, because the trip count is at most 10 bits, and %add49 (from 0) is
incremented by at most 1 per iteration. That is %add49 is at most 10 bits and
there is no need for the 16-bit mask of and operation.

Where and how should this optimization implemented?</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>