Originally reported as DevCom-1560717
_Countr_zero in this loop has unnecessary checks for zero input in the compiled code:
|
_Mx_magnitude >>= _Mx_trailing_zeroes;
|
|
do {
|
|
_Nx_magnitude >>= static_cast<unsigned long>(_Countr_zero(_Nx_magnitude));
|
|
if (_Mx_magnitude > _Nx_magnitude) {
|
|
_Common_unsigned _Temp = _Mx_magnitude;
|
|
_Mx_magnitude = _Nx_magnitude;
|
|
_Nx_magnitude = _Temp;
|
|
}
|
|
|
|
_Nx_magnitude -= _Mx_magnitude;
|
|
} while (_Nx_magnitude != 0U);
|
See the demo with __assume workaround: https://godbolt.org/z/Ts7ExjbYb
As the reported noted, compiler codegen could be improved.
But from the library, it can also be fixed by making specialized _Countr_zero that does not check for zero input, and calling the specialized version from std::gcd.
Originally reported as DevCom-1560717
_Countr_zeroin this loop has unnecessary checks for zero input in the compiled code:STL/stl/inc/numeric
Lines 567 to 577 in d8f03cf
See the demo with
__assumeworkaround: https://godbolt.org/z/Ts7ExjbYbAs the reported noted, compiler codegen could be improved.
But from the library, it can also be fixed by making specialized
_Countr_zerothat does not check for zero input, and calling the specialized version fromstd::gcd.