[llvm-bugs] [Bug 43111] New: Avoid reloads after vectorizer's runtime alias check
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 26 00:48:15 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43111
Bug ID: 43111
Summary: Avoid reloads after vectorizer's runtime alias check
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Loop Optimizer
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
Consider loop:
int foo(int *p, int *q) {
int s = 0;
for (int i = 0; i < 256; ++i) {
int k = p[i];
q[i] = 2*k;
s+= k;
int o = p[i];
s+= o;
}
return s;
}
Flags: clang -fno-unroll-loops -O3 loop.c -mavx2
In entry block there is a runtime check to check whether pointers do not alias.
entry:
%scevgep = getelementptr i32, i32* %q, i64 256
%scevgep23 = getelementptr i32, i32* %p, i64 256
%bound0 = icmp ugt i32* %scevgep23, %q
%bound1 = icmp ugt i32* %scevgep, %p
%found.conflict = and i1 %bound0, %bound1
br i1 %found.conflict, label %for.body, label %vector.body
Then, in loop body, we know there is no aliasing.
vector.body: ; preds = %entry,
%vector.body
%index = phi i64 [ %index.next, %vector.body ], [ 0, %entry ]
%vec.phi = phi <8 x i32> [ %7, %vector.body ], [ zeroinitializer, %entry ]
%0 = getelementptr inbounds i32, i32* %p, i64 %index
%1 = bitcast i32* %0 to <8 x i32>*
%wide.load = load <8 x i32>, <8 x i32>* %1, align 4, !tbaa !2, !alias.scope
!6
%2 = shl nsw <8 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1,
i32 1, i32 1>
%3 = getelementptr inbounds i32, i32* %q, i64 %index
%4 = bitcast i32* %3 to <8 x i32>*
store <8 x i32> %2, <8 x i32>* %4, align 4, !tbaa !2, !alias.scope !9,
!noalias !6
%5 = add nsw <8 x i32> %wide.load, %vec.phi
%6 = bitcast i32* %0 to <8 x i32>*
%wide.load25 = load <8 x i32>, <8 x i32>* %6, align 4, !tbaa !2, !alias.scope
!6
...
But we still reload p[i] '%wide.load25'..
Expected IR:
vector.body: ; preds = %entry,
%vector.body
%index = phi i64 [ %index.next, %vector.body ], [ 0, %entry ]
%vec.phi = phi <8 x i32> [ %5, %vector.body ], [ zeroinitializer, %entry ]
%0 = getelementptr inbounds i32, i32* %p, i64 %index
%1 = bitcast i32* %0 to <8 x i32>*
%wide.load = load <8 x i32>, <8 x i32>* %1, align 4, !tbaa !2, !alias.scope
!6
%2 = shl <8 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32
1, i32 1>
%3 = getelementptr inbounds i32, i32* %q, i64 %index
%4 = bitcast i32* %3 to <8 x i32>*
store <8 x i32> %2, <8 x i32>* %4, align 4, !tbaa !2, !alias.scope !9,
!noalias !6
...
--
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/20190826/9374e7b4/attachment.html>
More information about the llvm-bugs
mailing list