This reflects the behaviour of $shr/$shl, which sign-extend their A operands to the size of their output, then do a logical shift (shift in 0-bits).
This function has no hope of ever getting inlined anyway, and it speeds up yosys compile time by 7%.