<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - [AArch64] Loop counter duplicated during strength reduction for some 1-based loops"
href="https://llvm.org/bugs/show_bug.cgi?id=26913">26913</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[AArch64] Loop counter duplicated during strength reduction for some 1-based loops
</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>Linux
</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>chris@diamand.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mcrosier@codeaurora.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In some cases, the LoopStrengthReduce pass will duplicate the loop counter
unnecessarily. One example of this is the SingleSource/Benchmarks/Stanford/Perm
test.
For example, the following has its loop counter duplicated:
volatile int permarray[12];
void minimal_permute1(int n) {
int k;
for (k = n - 1; k >= 1; k--) {
minimal_permute1(n - 1);
permarray[k] = k;
}
}
The generated loop body is:
.LBB0_2: // %for.body
// =>This Inner Loop Header: Depth=1
mov w0, w19
sub x23, x22, #1 // =1
bl minimal_permute1
add x8, x21, x22, lsl #2
cmp x23, #1 // =1
mov x22, x23
stur w20, [x8, #-4]
sub w20, w20, #1 // =1
b.gt .LBB0_2
x23 and w20 are both holding the same value, but x23 is used as a 64-bit loop
counter, and w20 is the value stored in the array.
However, if I substitute k -> k + 1, to get the following equivalent loop:
void minimal_permute0(int n) {
int k;
for (k = n - 2; k >= 0; k--) {
minimal_permute0(n - 1);
permarray[k + 1] = k + 1;
}
}
Only one loop counter is used:
.LBB0_2: // %for.body
// =>This Inner Loop Header: Depth=1
mov w0, w19
bl minimal_permute0
str w20, [x21, x20, lsl #2]
sub x20, x20, #1 // =1
cmp x20, #0 // =0
b.gt .LBB0_2
This is caused by something in LoopStrengthReduce (verified with llc
-disable-lsr). I believe it's linked to having a 32-bit loop counter on a
64-bit arch.
This only happens when targeting AArch64. X86 and ARM are not affected.</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>