<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 - Loop latch info migrates to wrong loop."
href="https://bugs.llvm.org/show_bug.cgi?id=50060">50060</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Loop latch info migrates to wrong loop.
</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>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>jeroen.dobbelaere@synopsys.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=24777" name="attach_24777" title="test.ll: input program to opt">attachment 24777</a> <a href="attachment.cgi?id=24777&action=edit" title="test.ll: input program to opt">[details]</a></span>
test.ll: input program to opt
This bug is created for the problem mentioned in
<a href="https://lists.llvm.org/pipermail/llvm-dev/2021-April/149782.html">https://lists.llvm.org/pipermail/llvm-dev/2021-April/149782.html</a>
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: <a href="https://www.godbolt.org/z/EW95YjW8h">https://www.godbolt.org/z/EW95YjW8h</a>
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.</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>