<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 - [CGP] move a sub that's part of a rotate into the block with shifts+or"
href="https://bugs.llvm.org/show_bug.cgi?id=37417">37417</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[CGP] move a sub that's part of a rotate into the block with shifts+or
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Forking this off from <a class="bz_bug_link
bz_status_NEW "
title="NEW - MSVC rotate intrinsics don't (just) generate rotates on x86-64"
href="show_bug.cgi?id=37387">bug 37387</a>.
LICM (I think) may split a rotate pattern in IR across blocks. Once that
happens, DAGCombiner::MatchRotate() can't put the pieces back together again.
CodeGenPrepare must reverse LICM to make the rotate visible to the DAG when the
target has a legal/custom ROTL/ROTR node.
Here's a basic example (should verify that the unrolled case works too):
void rotateInLoop(unsigned *x, unsigned N, unsigned *a, int b) {
for (unsigned i = 0; i < N; ++i)
x[ (a[i] >> b) | (a[i] << (32 - b)) ] = i; // shift amt is loop invariant
}
$ ./clang -O2 ror.c -S -o - -fno-unroll-loops -emit-llvm
...
define void @rotateInLoop(i32* nocapture %x, i32 %b, i32* nocapture readonly
%a, i32 %N) {
entry:
%cmp12 = icmp eq i32 %N, 0
br i1 %cmp12, label %for.cond.cleanup, label %for.body.lr.ph
for.body.lr.ph:
%sub = sub nsw i32 32, %b <--- this should be moved back into the loop
%wide.trip.count = zext i32 %N to i64
br label %for.body
for.cond.cleanup:
ret void
for.body:
%indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
%0 = load i32, i32* %arrayidx, align 4, !tbaa !3
%shr = lshr i32 %0, %b
%shl = shl i32 %0, %sub
%or = or i32 %shr, %shl
%idxprom3 = zext i32 %or to i64
%arrayidx4 = getelementptr inbounds i32, i32* %x, i64 %idxprom3
%1 = trunc i64 %indvars.iv to i32
store i32 %1, i32* %arrayidx4, align 4, !tbaa !3
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}</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>