-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Originally reported as DevCom-1560717
_Countr_zero in this loop has unnecessary checks for zero input in the compiled code:
Lines 567 to 577 in d8f03cf
| _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.
Reactions are currently unavailable