<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82242>82242</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[X86] Attempt to perform AVX1 v8i32 integer comparisons as v8f32
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
```cpp
__v8si vcmpi(__v8si x) {
__v8si M = (__v8si) {K,K,K,K,K,K,K,K};
x &= M;
return x == M;
}
__v8si vcmpf(__v8si x) {
__v8si M = (__v8si) {K,K,K,K,K,K,K,K};
x &= M;
return __builtin_convertvector(x,__v8sf) == __builtin_convertvector(M, __v8sf);
}
```
```ll
define <8 x i32> @vcmpi(<8 x i32> %x) {
%and = and <8 x i32> %x, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%cmp = icmp eq <8 x i32> %and, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%sext = sext <8 x i1> %cmp to <8 x i32>
ret <8 x i32> %sext
}
define <8 x i32> @vcmpf(<8 x i32> %x) {
%and = and <8 x i32> %x, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%conv = sitofp <8 x i32> %and to <8 x float>
%cmp = fcmp oeq <8 x float> %conv, <float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00>
%sext = sext <8 x i1> %cmp to <8 x i32>
ret <8 x i32> %sext
}
```
AVX1 targets have to split/concat 256-bit integer comparisons, but if we can confirm that the integer values are exactly representable as integers then it can be worth converting to floats and perform as a fp comparison.
llvm-mca: https://llvm.godbolt.org/z/5Tns64zGP
This came up on some sincos implementations where most of the code is 256-bit fp, but we were having to convert to int to compute the quadrant (0 - 3) special cases.
Invert of #82241
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVt1u4zYTfRrqZhBDGlq2cqELx15_-LAIULSLYu8CihpZbCVSS1KKN09fkJazduItChT9M2xoxBnNmXNmSEs4pw6aqGT5A8t3iRh9a2z548efVG90Upn6a8lW6ekrh4GlO5Zunp6mwimYZD8ohsV8e2R4D2z9cIoBAJgdj8D4Dl4D57CPDLff_613jF9kOgLDVcjyeLVsyY9WBy_fXXtDgpPxtuLm31Dx01M1qs4r_SSNnsj6iaQ3lmFxZLiNqE1EPfH6fvgjwy28xt-gf27em9uuOy3U1ChNwPi2gCMojox_ALZMz71948D8jWYMc6HrKNfp-j58G1YVR-DB_jMG_3AWkmEu-yHCqmDQl_fQQtd_Gbijo4_os3GCzmbkUJE31xWdH7bk35castyc299rT_MH2vNP9sfo6SSR8qYZbvbnQqWmM8Lf7nATDPOtxefQM8pMIS4DX6TxQwwf0jS4_hPrf_d0XR8Lm58_Z-CFPZB30IqJAoAbOuUZ7qXRUnjAfHVXKQ9KezqQBWn6QVjljHaBVTV6UA08E0ihQRrdKNuDb4UH39LrU5PoRnIgLAEdhfTdV7A0WHKkvag6AuHOsS48qEH5mLEieDbWtzCfgEofQpFRTBdneyDbGNuHDAKa4aLAxeWW6rqpv-ulYHwDrfeDY3zDcM9wHzyLg6kr0_mFsQeG-xeG-_yTdqvly_9-uMzyqVUOpOgJxgGMBmd6Aqe0NA5UP3TUB0JeGe3guSVL0BvnwTRRDWlqAuVeNW2Gs4TPBM8huhXTzHDmG0yl4yUyGz3FVF9GUVuhffi3SuEubMd7cANJJTqQwpG7Yv__UzLTAENeIC6zpC55fc_vRUJltk4Lvswx40lbUlHRGnNaNdm6qnla8ELk-aria5HXlIlElZjiMsXsPkNMM76Q6xWlIseskSkRJ7ZMqReqW0RljT0kyrmRyoCLSScq6lx880CshPyVdM345nOxYogMtwyxV85RfWcGr3r1EuUMvnyX2DL2sRoPji3TTjnvvqF45bv4ShNy5TvYeE_9ELU7D0mc-KkI59aNgQ4zNBUNx2S0XXk9JQfl27FaSNPPIzNf7gZrfiEZdkxk6RjuI9HfAgAA___BNJ4O">