<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 - SimplifyCFG destroying canonical loop structure"
href="https://bugs.llvm.org/show_bug.cgi?id=33605">33605</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>SimplifyCFG destroying canonical loop structure
</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>Windows NT
</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>bmakam@codeaurora.org
</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=18718" name="attach_18718" title="test.ll">attachment 18718</a> <a href="attachment.cgi?id=18718&action=edit" title="test.ll">[details]</a></span>
test.ll
In attached test case, there a loop latch block whose terminator is an
unconditional branch. When simplifyCFG simplifies the latch block it folds it
into the loop header. This destroys the canonical loop structure as it results
in multiple backedges. This prevents later optimizations from being applied
(e.g. loop unroll and loop vectorization). As in this example, LoopSimplify
turns it into a nested loop because there are multiple backedges and now this
loop cannot be unrolled.
The attached testcase(test.ll) is from this c code:
$cat test.c
void foo();
bool test(int a, int b, int *c) {
bool changed = false;
for (unsigned int i = 2; i--;) {
int r = a | b;
if ( r != c[i]) {
c[i] = r;
foo();
changed = true;
}
}
return changed;
}
With simplifyCFG:
$ opt < test.ll -simplifycfg -loop-rotate -loop-unroll -debug -disable-output
Args: opt -simplifycfg -loop-rotate -loop-unroll -debug -disable-output
Looking to fold if.end into for.cond
Killing Trivial BB:
if.end: ; preds = %if.then, %for.body
%changed.1.off0 = phi i1 [ true, %if.then ], [ %changed.0.off0, %for.body ]
br label %for.cond
LoopSimplify: Splitting out a new outer loop
Loop Unroll: F[test] Loop %for.cond
Loop Size = 9
will not try to unroll loop with runtime trip count -unroll-runtime not given
Loop Unroll: F[test] Loop %for.cond.outer
Loop Size = 13
will not try to unroll loop with runtime trip count -unroll-runtime not given
Without simplifyCFG:
$ opt < new.ll -loop-rotate -loop-unroll -debug -disable-output
Args: opt -loop-rotate -loop-unroll -debug -disable-output
LoopRotation: rotating Loop at depth 1 containing:
%for.cond<header><exiting>,%for.body,%if.then,%if.end<latch>
Inserted PHI: %changed.0.off01 = phi i1 [ false, %entry ], [
%changed.0.off0, %for.cond ]
Inserted PHI: %dec2 = phi i32 [ 1, %entry ], [ %dec, %for.cond ]
LoopRotation: into Loop at depth 1 containing:
%for.body<header>,%if.then,%if.end<latch><exiting>
Loop Unroll: F[test] Loop %for.body
Loop Size = 12
Trip Count = 2
Trip Multiple = 2
COMPLETELY UNROLLING loop %for.body with trip count 2!
Merging:
for.body.1: ; preds = %if.end
%or.1 = or i32 %a, %b
%idxprom.1 = sext i32 %dec to i64
%arrayidx.1 = getelementptr inbounds i32, i32* %c, i64 %idxprom.1
%1 = load i32, i32* %arrayidx.1, align 4
%cmp.1 = icmp eq i32 %or.1, %1
br i1 %cmp.1, label %if.end.1, label %if.then.1
into:
if.end: ; preds = %if.then, %for.body
%changed.1.off0 = phi i1 [ true, %if.then ], [ false, %for.body ]
%dec = add nsw i32 1, -1
%tobool = icmp eq i32 1, 0
br label %for.body.1
Merging:
for.cond.cleanup: ; preds = %if.end.1
%changed.0.off0.lcssa = phi i1 [ %changed.1.off0.1, %if.end.1 ]
ret i1 %changed.0.off0.lcssa
into:
if.end.1: ; preds = %if.then.1, %if.end
%changed.1.off0.1 = phi i1 [ true, %if.then.1 ], [ %changed.1.off0, %if.end ]
%dec.1 = add nsw i32 %dec, -1
%tobool.1 = icmp eq i32 %dec, 0
br label %for.cond.cleanup</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>