[llvm-bugs] [Bug 40706] New: A missed mid-end opt to remove unnecessary instrs inside the loop

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 12 13:23:49 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40706

            Bug ID: 40706
           Summary: A missed mid-end opt to remove unnecessary instrs
                    inside the loop
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: ning.xie at huawei.com
                CC: llvm-bugs at lists.llvm.org

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?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190212/9aacf51c/attachment.html>


More information about the llvm-bugs mailing list