https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114514
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- For non constant clang produces: ``` signedshiftright: movzbl %dil, %eax movd %eax, %xmm1 psrlw %xmm1, %xmm0 pcmpeqd %xmm2, %xmm2 psrlw %xmm1, %xmm2 movdqa .LCPI0_0(%rip), %xmm3 # xmm3 = [32896,32896,32896,32896,32896,32896,32896,32896] psrlw %xmm1, %xmm3 psrlw $8, %xmm2 punpcklbw %xmm2, %xmm2 # xmm2 = xmm2[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7] pshuflw $0, %xmm2, %xmm1 # xmm1 = xmm2[0,0,0,0,4,5,6,7] pshufd $0, %xmm1, %xmm1 # xmm1 = xmm1[0,0,0,0] pand %xmm1, %xmm0 pxor %xmm3, %xmm0 psubb %xmm3, %xmm0 retq unsignedshiftrtight: movzbl %dil, %eax movd %eax, %xmm1 psrlw %xmm1, %xmm0 pcmpeqd %xmm2, %xmm2 psrlw %xmm1, %xmm2 psrlw $8, %xmm2 punpcklbw %xmm2, %xmm2 # xmm2 = xmm2[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7] pshuflw $0, %xmm2, %xmm1 # xmm1 = xmm2[0,0,0,0,4,5,6,7] pshufd $0, %xmm1, %xmm1 # xmm1 = xmm1[0,0,0,0] pand %xmm1, %xmm0 retq ``` I am not sure which way is faster here though.