<html>
<head>
<base href="https://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 --- - [InstCombine] canonicalize extractelement reductions with shuffles"
href="https://llvm.org/bugs/show_bug.cgi?id=25808">25808</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombine] canonicalize extractelement reductions with shuffles
</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>normal
</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>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Hal suggested something like this in D15250:
<a href="http://reviews.llvm.org/D15250">http://reviews.llvm.org/D15250</a>
$ cat reduction.c
typedef int v4i __attribute__((vector_size(16)));
int foo(v4i x) {
return x[0] + x[1] + x[2] + x[3];
}
$ ./clang -O1 reduction.c -S -o - -emit-llvm
...
define i32 @foo(<4 x i32> %x) #0 {
entry:
%vecext = extractelement <4 x i32> %x, i32 0
%vecext1 = extractelement <4 x i32> %x, i32 1
%add = add nsw i32 %vecext, %vecext1
%vecext2 = extractelement <4 x i32> %x, i32 2
%add3 = add nsw i32 %add, %vecext2
%vecext4 = extractelement <4 x i32> %x, i32 3
%add5 = add nsw i32 %add3, %vecext4
ret i32 %add5
}
InstCombine should be able to transform this into vector math + shuffles to
reduce the instruction count for any vector with 4+ elements:
%shuf1 = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 2, i32
3, i32 undef, i32 undef> ; shift left by 2 elements
%rdx1 = add <4 x i32> %x, %shuf1 ; 0+2 : 1+3 : undef : undef
%shuf2 = shufflevector <4 x i32> %rdx1, <4 x i32> undef, <4 x i32> <i32 1,
i32 undef, i32 undef, i32 undef> ; shift left 1 element
%rdx2 = add <4 x i32> %rdx1, %shuf2 ; 0+1+2+3 in first vec elt
%31 = extractelement <4 x i32> %rdx2, i32 0
This pattern would then be recognized as a canonical reduction.
I was looking for a similar transform to help <a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Missed optimisation - horizontal max for vectors is not optimised."
href="show_bug.cgi?id=23116">bug 23116</a>.</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>