<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 --- - vectorize repeated scalar ops that don't get put back into a vector"
href="https://llvm.org/bugs/show_bug.cgi?id=31879">31879</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>vectorize repeated scalar ops that don't get put back into a vector
</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>Transformation Utilities
</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>Forking this off from <a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Squaring a complex float gives inefficient code"
href="show_bug.cgi?id=31866">bug 31866</a>:
; For vector <x0, x1>, return x0^2 + x1^2
define float @f(<2 x float> %x) {
%x0 = extractelement <2 x float> %x, i32 0
%x1 = extractelement <2 x float> %x, i32 1
%x0x0 = fmul float %x0, %x0
%x1x1 = fmul float %x1, %x1
%add = fadd float %x0x0, %x1x1
ret float %add
}
We should recognize patterns where the same scalar ops are applied to all
extracted elements in a vector and turn that into vector ops followed by
extraction:
define float @f(<2 x float> %x) {
%xx = fmul <2 x float> %x, %x
%x0x0 = extractelement <2 x float> %xx, i32 0
%x1x1 = extractelement <2 x float> %xx, i32 1
%add = fadd float %x0x0, %x1x1
ret float %add
}
The SLP vectorizer already handles the case where we insert back into a vector,
so we can loosen the restriction and use the existing SLP logic to catch this
case?
define <2 x i8> @g(<2 x i8> %x) {
%x0 = extractelement <2 x i8> %x, i32 0
%x1 = extractelement <2 x i8> %x, i32 1
%x0x0 = mul i8 %x0, %x0
%x1x1 = mul i8 %x1, %x1
%ins1 = insertelement <2 x i8> undef, i8 %x0x0, i32 0
%ins2 = insertelement <2 x i8> %ins1, i8 %x1x1, i32 1
ret <2 x i8> %ins2
}
$ ./opt -slp-vectorizer scalarizedmath.ll -S
define <2 x i8> @g(<2 x i8> %x) {
%1 = mul <2 x i8> %x, %x
%2 = extractelement <2 x i8> %1, i32 0
%ret = insertelement <2 x i8> undef, i8 %2, i32 0
%3 = extractelement <2 x i8> %1, i32 1
%ret2 = insertelement <2 x i8> %ret, i8 %3, i32 1
ret <2 x i8> %ret2
}
Instcombine can then clean up the useless inserts and extracts.</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>