[llvm-bugs] [Bug 37417] New: [CGP] move a sub that's part of a rotate into the block with shifts+or
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri May 11 09:04:30 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37417
Bug ID: 37417
Summary: [CGP] move a sub that's part of a rotate into the
block with shifts+or
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: spatel+llvm at rotateright.com
CC: llvm-bugs at lists.llvm.org
Forking this off from bug 37387.
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
}
--
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/20180511/88a097ce/attachment.html>
More information about the llvm-bugs
mailing list