The patch folds
(ashr (shl, a, [56,48,32,24,16]), SarConst)
into
(shl, (sext (a), [56,48,32,24,16] - SarConst))
or into
(lshr, (sext (a), SarConst - [56,48,32,24,16]))
depending on sign of (SarConst - [56,48,32,24,16])
sexts in X86 are MOVs. The MOVs have the same code size as above SHIFTs (only SHIFT on 1 has lower code size).
However the MOVs have 2 advantages to SHIFTs on x86:
- MOVs can write to a register that differs from source
- MOVs accept memory operands
I think you will need to add a test for N0.hasOneUse() as well here - otherwise there is a likely chance that the SHL will still need to be performed.