https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82889
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- On the other side, in REE nonzero_bits on the operand of SIGN_EXTEND on the last testcase above doesn't return 0x7fffffff, but 0xffffffff, maybe it is too late to use SSA_NAME_RANGE_INFO at that point. So, perhaps use range info (possibly improved with the on-demand VRP) in the expander when emitting a SIGN_EXTEND or ZERO_EXTEND and ask the backend what is generally cheaper to use if the value range indicates value between 0 and signed integral maximum of the corresponding precision. Then we'd use ZERO_EXTEND on x86 any time we'd otherwise emit SIGN_EXTEND if range info tells us the MSB is clear.