<html>
<head>
<base href="http://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 --- - should be able to simplify vector loop induction variables"
href="http://llvm.org/bugs/show_bug.cgi?id=20850">20850</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>should be able to simplify vector loop induction variables
</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>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>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider this testcase from PR20849:
#include <stdio.h>
int main() {
int i;
unsigned char in[1000];
for (i = 0; i < 1000; i++)
in[i] = i % 127;
for (i = 0; i < 1000; i++)
printf("%d\n", in[i]);
return 0;
}
The first loop produces the following IR at -O3:
entry:
%in = alloca [1000 x i8], align 16
%0 = getelementptr inbounds [1000 x i8]* %in, i64 0, i64 0
call void @llvm.lifetime.start(i64 1000, i8* %0) #1
br label %vector.body
vector.body: ; preds = %vector.body,
%entry
%index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
%1 = trunc i64 %index to i32
%broadcast.splatinsert22 = insertelement <4 x i32> undef, i32 %1, i32 0
%broadcast.splat23 = shufflevector <4 x i32> %broadcast.splatinsert22, <4 x
i32> undef, <4 x i32> zeroinitializer
%induction24 = add <4 x i32> %broadcast.splat23, <i32 0, i32 1, i32 2, i32 3>
%induction25 = add <4 x i32> %broadcast.splat23, <i32 4, i32 5, i32 6, i32 7>
%2 = srem <4 x i32> %induction24, <i32 127, i32 127, i32 127, i32 127>
%3 = srem <4 x i32> %induction25, <i32 127, i32 127, i32 127, i32 127>
%4 = trunc <4 x i32> %2 to <4 x i8>
%5 = trunc <4 x i32> %3 to <4 x i8>
%6 = getelementptr inbounds [1000 x i8]* %in, i64 0, i64 %index
%7 = bitcast i8* %6 to <4 x i8>*
store <4 x i8> %4, <4 x i8>* %7, align 8, !tbaa !1
%.sum26 = or i64 %index, 4
%8 = getelementptr [1000 x i8]* %in, i64 0, i64 %.sum26
%9 = bitcast i8* %8 to <4 x i8>*
store <4 x i8> %5, <4 x i8>* %9, align 4, !tbaa !1
%index.next = add i64 %index, 8
%10 = icmp eq i64 %index.next, 1000
br i1 %10, label %for.body3.preheader, label %vector.body, !llvm.loop !4
This is dumb. Instead of a broadcast and two adds in each iteration of the
loop, we should rewrite the loop to start at <i32 0, i32 1, i32 2, i32 3> and
<i32 4, i32 5, i32 6, i32 7>, and add 8 to each element on each iteration.</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>