<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 - pmuludq may generate an explicit mask beforehand."
href="https://bugs.llvm.org/show_bug.cgi?id=40142">40142</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>pmuludq may generate an explicit mask beforehand.
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>7.0
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>husseydevin@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>This is a regression in 7.0.0.
I was trying to mess with multiply code for SSE, and found that Clang
7.0.0-trunk (regression from 6) will do an explicit mask occasionally before a
pmuludq. This results in either a pand or a pblendq, depending on whether
SSE4.1 is enabled.
This is obviously redundant, as pmuludq clears the odd lanes automatically.
This C code:
#include <emmintrin.h>
__m128i pmuludq_square(__m128i val)
{
return _mm_mul_epu32(val, val);
}
with -O3, optimizes to this.
U64x2 pmuludq_square(U64x2 val)
{
#ifdef __SSE4_1__
const U32x4 mask = { 0, 0, 0, 0 };
val = (U64x2)__builtin_shufflevector((U32x4)val, mask, 0, 4, 2, 4);
#else
const U64x2 mask = { 0xFFFFFFFF, 0xFFFFFFFF };
val &= mask;
#endif
return _mm_mul_epu32(val, val);
}
<a href="https://godbolt.org/z/47NWxr">https://godbolt.org/z/47NWxr</a>
LLVM code:
define <2 x i64> @pmuludq_square(<2 x i64> %val)
{
%v32 = bitcast <2 x i64> %val to <4 x i32>
%mul = tail call <2 x i64> @llvm.x86.sse2.pmulu.dq(<4 x i32> %v32, <4 x
i32> %v32)
ret <2 x i64> %mul
}
declare <2 x i64> @llvm.x86.sse2.pmulu.dq(<4 x i32>, <4 x i32>) #1
opt -O3:
define <2 x i64> @pmuludq_square(<2 x i64> %val) local_unnamed_addr #0 {
%1 = and <2 x i64> %val, <i64 4294967295, i64 4294967295>
%2 = mul nuw <2 x i64> %1, %1
ret <2 x i64> %2
}
<a href="https://godbolt.org/z/qTc2Zg">https://godbolt.org/z/qTc2Zg</a>
Related to <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - instcombine forms illegal <2 x i64> multiply with trunc/zext"
href="show_bug.cgi?id=40032">bug 40032</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>