<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 --- - Unnecessary instructions generated for logical vector shift by (__m128i)0" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23821&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=9E_7n11ukhxMNtcmc8151cNHsR1_mlNV76LipYIkQGY&s=jmyneLM6dlgfMEhQe2Qg-JlG3QzbuzhcBAjYyghOndQ&e=">23821</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unnecessary instructions generated for logical vector shift by (__m128i)0
</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>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>charles_li@playstation.sony.com
</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>On X86, logically shifting a vector by “(__m128i) 0” will cause unnecessary
instructions at -O2
( "(__m128i) 0" being a 128-bit vector constant of value 0 )
Here is an example of poor code gen assembling the following results in
a vector xor followed by vector shift logical left.
Since xor of a register with itself is 0 and shifting a value by 0 is itself,
the 2 instructions are redundant.
test.cpp:
__m128i logic_left_shift_vec_0_of_64( __m128i a ) {
return _mm_sll_epi64( a, (__m128i) {0, 0} );
}
clang test.cpp -S -O2
test.s:
vpxor %xmm1, %xmm1, %xmm1
vpsllq %xmm1, %xmm0, %xmm0
retq
Here is an example of where Clang does good code gen, in this intrinsic, 0 is a
scalar integer
When assembling at -O2, only return instruction is generated.
test2.cpp:
__m128i logic_left_shift_int_0_of_64( __m128i a ) {
return _mm_slli_epi64( a, 0 );
}
clang test2.cpp -S -O2
test2.s:
retq
Here is another example of good code gen, Arithmetic shift of a vector by
“(__m128i) 0”.
In this example, despite the 0 being a vector immediate, Clang is still able
to deduce that shifting by 0 has no effect.
__m128i arith_right_shift_int_0_of_32( __m128i a ) {
return _mm_srai_epi32( a, 0 );
}
clang test3.cpp -S -O2
retq
Here are all of the vector shift intrinsics that results in poor code gen.
/***************************************************/
#include <x86intrin.h>
// Logical shift by vec immediate zero
__m128i logic_left_shift_vec_0_of_64( __m128i a ) {
return _mm_sll_epi64( a, (__m128i) {0, 0} );
}
__m128i logic_right_shift_vec_0_of_64( __m128i a ) {
return _mm_srl_epi64( a, (__m128i) {0, 0} );
}
__m128i logic_left_shift_vec_0_of_32( __m128i a ) {
return _mm_sll_epi32( a, (__m128i) {0, 0} );
}
__m128i logic_right_shift_vec_0_of_32( __m128i a ) {
return _mm_srl_epi32( a, (__m128i) {0, 0} );
}
__m128i logic_left_shift_vec_0_of_16( __m128i a ) {
return _mm_sll_epi16( a, (__m128i) {0, 0} );
}
__m128i logic_right_shift_vec_0_of_16( __m128i a ) {
return _mm_srl_epi16( a, (__m128i) {0, 0} );
}
/***************************************************/
For comparison, here are the other vector shift intrinsics
that result in good code gen.
/***************************************************/
// Logical shift by int immediate zero
__m128i logic_left_shift_int_0_of_64( __m128i a ) {
return _mm_slli_epi64( a, 0 );
}
__m128i logic_right_shift_int_0_of_64( __m128i a ) {
return _mm_srli_epi64( a, 0 );
}
__m128i logic_left_shift_int_0_of_32( __m128i a ) {
return _mm_slli_epi32( a, 0 );
}
__m128i logic_right_shift_int_0_of_32( __m128i a ) {
return _mm_srli_epi32( a, 0 );
}
__m128i logic_left_shift_int_0_of_16( __m128i a ) {
return _mm_slli_epi16( a, 0 );
}
__m128i logic_right_shift_int_0_of_16( __m128i a ) {
return _mm_srli_epi16( a, 0 );
}
// Arithmetic Shifts
__m128i arith_right_shift_vec_0_of_32( __m128i a ) {
return _mm_sra_epi32( a, (__m128i) {0, 0} );
}
__m128i arith_right_shift_int_0_of_32( __m128i a ) {
return _mm_srai_epi32( a, 0 );
}
__m128i arith_right_shift_vec_0_of_16( __m128i a ) {
return _mm_sra_epi16( a, (__m128i) {0, 0} );
}
__m128i arith_right_shift_int_0_of_16( __m128i a ) {
return _mm_srai_epi16( a, 0 );
}
/***************************************************/</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>