[llvm-bugs] [Bug 50060] New: Loop latch info migrates to wrong loop.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 21 08:31:25 PDT 2021


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

            Bug ID: 50060
           Summary: Loop latch info migrates to wrong loop.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: jeroen.dobbelaere at synopsys.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 24777
  --> https://bugs.llvm.org/attachment.cgi?id=24777&action=edit
test.ll: input program to opt

This bug is created for the problem mentioned in
https://lists.llvm.org/pipermail/llvm-dev/2021-April/149782.html

In a program with 3 nested loops (See attachment), a loop annotation on the
middle loop migrates to the outer loop.

An example of pass order (deduced from -O2) that shows the problem:
  opt -S --simplifycfg --sroa --simplifycfg  --instcombine --licm --simplifycfg
--loop-simplify --loop-rotate --licm --simplifycfg --loop-simplify -loops
-enable-new-pm=0 test.ll -o -

Also see: https://www.godbolt.org/z/EW95YjW8h 

It has following panes:
- on the left: the source code
- top right: the loop info after the passes mentioned above, except for the
last '--loop-simplify'.
  This shows that %for.cond.cleanup3 serves as a latch for two loops. (outer
and middle)

  Loop at depth 1 containing:
%do.body<header>,%for.cond1.preheader,%for.body4,%for.cond.cleanup3<latch>
      Loop at depth 2 containing:
%for.cond1.preheader<header>,%for.body4,%for.cond.cleanup3<latch><exiting>
          Loop at depth 3 containing: %for.body4<header><latch><exiting>

- middle right: same info, now with the last '--loop-simplify'. It states that
'%do.body.loopexit' is
  the latch for the outer loop.

  Loop at depth 1 containing:
%do.body<header>,%for.cond1.preheader,%for.body4,%for.cond.cleanup3,%for.body4.preheader,%for.cond.cleanup3.loopexit,%do.body.loopexit<latch>
    Loop at depth 2 containing:
%for.cond1.preheader<header>,%for.body4,%for.cond.cleanup3<latch><exiting>,%for.body4.preheader,%for.cond.cleanup3.loopexit
        Loop at depth 3 containing: %for.body4<header><latch><exiting>


- bottom right: resulting code, corresponding to the 'middle right' pane. There
you can see that
  the '%do.body.loopexit' contains a branch with an annotation that was
originally on the middle loop.
  This annotation also states 'llvm.loop.mustprogress'.
  The branch in the latch block for the middle loop (%for.cond.cleanup3) does
not contain a loop annotation
  any more.

  do.body.loopexit:                                 ; preds =
%for.cond.cleanup3
    br label %do.body, !llvm.loop !6


   ...
  for.cond.cleanup3:                                ; preds =
%for.cond.cleanup3.loopexit, %for.cond1.preheader
    %inc7 = add nuw nsw i32 %j.08, 1
    %cmp = icmp ult i32 %inc7, 3
    br i1 %cmp, label %for.cond1.preheader, label %do.body.loopexit


The migration is a problem, as now, the outer loop gets a wrong annotation
('mustprogress', where it is not).

Also notice that the initial annotation on the outer loop (!llvm.loop !10)
disappears during the optimization passes.

-- 
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/20210421/920d5828/attachment.html>


More information about the llvm-bugs mailing list