<div dir="ltr">Hi all, <div><br></div><div>Here is a snippet of code taken from NumPy and the corresponding output when using clang 10.0 (or even clang 12.0). Can also view the code here: <a href="https://godbolt.org/z/Peznjx">https://godbolt.org/z/Peznjx</a></div><div><br></div><div>The compiler optimizes and removes the first blendv_ps instruction (i.e eliminates the temp1 variable all together). The goal of this instruction was to prevent an overflow flag generated in the following multiplication instruction. By eliminating this instruction, the resulting code causes an unintended fp overflow flag which I think is incorrect behavior.  </div><div><br></div><div>C code: </div><div><br></div><div>__m256 fma_get_mantissa(__m256 x)<br>{<br>    __m256 two_power_100 = _mm256_castsi256_ps(_mm256_set1_epi32(0x71800000));<br>    __m256 denormal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_LT_OQ);<br>    __m256 normal_mask = _mm256_cmp_ps(x, _mm256_set1_ps(FLT_MIN), _CMP_GE_OQ);<br><br>    __m256 temp1 = _mm256_blendv_ps(x, _mm256_set1_ps(0.0f), normal_mask);<br>    __m256 temp = _mm256_mul_ps(temp1, two_power_100);<br>    x = _mm256_blendv_ps(x, temp, denormal_mask);<br><br>    __m256i mantissa_bits = _mm256_set1_epi32(0x7fffff);<br>    __m256i exp_126_bits  = _mm256_set1_epi32(126 << 23);<br>    return _mm256_castsi256_ps(<br>                _mm256_or_si256(<br>                    _mm256_and_si256(<br>                        _mm256_castps_si256(x), mantissa_bits), exp_126_bits));</div><div>} <br></div><div><br></div><div>object code output from clang: </div><div><br></div><div>.LCPI0_0:<br>        .long   0x00800000                      # float 1.17549435E-38<br>.LCPI0_1:<br>        .long   0x71800000                      # float 1.2676506E+30<br>.LCPI0_2:<br>        .long   4294967170                      # 0xffffff82<br>.LCPI0_3:<br>        .long   0xc2c80000                      # float -100<br>fma_get_exponent:                       # @fma_get_exponent<br>        vbroadcastss    ymm1, dword ptr [rip + .LCPI0_0] # ymm1 = [1.17549435E-38,1.17549435E-38,1.17549435E-38,1.17549435E-38,1.17549435E-38,1.17549435E-38,1.17549435E-38,1.17549435E-38]<br>        vcmpltps        ymm2, ymm0, ymm1<br>        vbroadcastss    ymm3, dword ptr [rip + .LCPI0_1] # ymm3 = [1.2676506E+30,1.2676506E+30,1.2676506E+30,1.2676506E+30,1.2676506E+30,1.2676506E+30,1.2676506E+30,1.2676506E+30]<br>        <b>vmulps  ymm3, ymm0, ymm3</b><br>        vcmpnleps       ymm1, ymm1, ymm0<br>        vandps  ymm1, ymm1, ymm3<br>        vblendvps       ymm0, ymm0, ymm1, ymm2<br>        vpsrld  ymm0, ymm0, 23<br>        vpbroadcastd    ymm1, dword ptr [rip + .LCPI0_2] # ymm1 = [4294967170,4294967170,4294967170,4294967170,4294967170,4294967170,4294967170,4294967170]<br>        vpaddd  ymm0, ymm0, ymm1<br>        vcvtdq2ps       ymm0, ymm0<br>        vbroadcastss    ymm1, dword ptr [rip + .LCPI0_3] # ymm1 = [-1.0E+2,-1.0E+2,-1.0E+2,-1.0E+2,-1.0E+2,-1.0E+2,-1.0E+2,-1.0E+2]<br>        vaddps  ymm1, ymm0, ymm1<br>        vblendvps       ymm0, ymm0, ymm1, ymm2<br>        ret<br></div><div><br></div><div>Raghuveer</div><div><br></div><div><br></div><div><br></div><div><br></div></div>