<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 - Failure to remove before/after reverse shuffles from loop with decrementing iterator"
href="https://bugs.llvm.org/show_bug.cgi?id=49616">49616</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to remove before/after reverse shuffles from loop with decrementing iterator
</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>Windows NT
</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>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>anton.a.afanasyev@gmail.com, florian_hahn@apple.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/dWTd9e">https://godbolt.org/z/dWTd9e</a>
void loop_dec(unsigned short *p, int max, int n) {
for (int i = 0; i < (n & 31); i++) {
unsigned m = *--p;
*p = (unsigned short)(m >= max ? m-max : 0);
}
}
By decrementing the pointer in the loop we end up with loop bodies like this:
52:
%53 = phi i64 [ %41, %40 ], [ %64, %52 ]
%54 = sub i64 0, %53
%55 = getelementptr inbounds i16, i16* %51, i64 %54
%56 = bitcast i16* %55 to <4 x i16>*
%57 = load <4 x i16>, <4 x i16>* %56, align 2, !tbaa !2
%58 = shufflevector <4 x i16> %57, <4 x i16> poison, <4 x i32> <i32 3, i32 2,
i32 1, i32 0>
%59 = zext <4 x i16> %58 to <4 x i32>
%60 = call <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %59, <4 x i32> %50)
%61 = trunc <4 x i32> %60 to <4 x i16>
%62 = shufflevector <4 x i16> %61, <4 x i16> poison, <4 x i32> <i32 3, i32 2,
i32 1, i32 0>
%63 = bitcast i16* %55 to <4 x i16>*
store <4 x i16> %62, <4 x i16>* %63, align 2, !tbaa !2
%64 = add i64 %53, 4
%65 = icmp eq i64 %64, %45
br i1 %65, label %66, label %52, !llvm.loop !9
AFAICT we should be able to remove both these 'reverse' shufflevectors.
I'm not sure if we should be trying to fix this in InstCombine/VectorCombine or
inside the LoopVectorizer.</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>