Differentiate arithmetic (ashr) and logical shift right (lshr) in LLVM frontend
We do not differentiate between the LLVM instructions ashr
and lshr
.
Currently, both are handled as C's right-shift (>>
).
Instead, we should differentiate between the two operations.
GNU C performs an arithmetic shift for signed types and a logical shift for unsigned types, so we can control the behavior by casting the first operator's type accordingly: We can force a logical shift by casting the value to an unsigned value, and we can force an arithmetic shift by casting the value to a signed value.
Example 1:
ashr i32 4, 1
is equal to
((signed int) 4) >> 1
Example 2:
lshr i32 4, 1
is equal to
((unsigned int) 4) >> 1