[LLVMdev] Shifts that use only 5 LSBs.

Eli Friedman eli.friedman at gmail.com
Tue Dec 16 16:57:35 PST 2008


On Tue, Dec 16, 2008 at 3:36 PM, Daniel M Gessel <gessel at apple.com> wrote:
> I'm working on a Target that only uses the 5 lsbs of the shift amount.

Okay, that's quite common... x86 is the same.

> I only have 32 bit registers, no 64 bit, so 64 bit math is emulated,
> LLVM doing the transformations whenever I can get it to.

x86 is the same.

> I think I'm seeing a case where it ultimately looks like a standard
> multiword shift (from e.g. Hacker's Delight) is being inline expanded
> that assumes at least 6 bits of the shift is paid attention to (i.e.
> it looks like it assumes x >> 32 == 0 if x is 32 bits, but for me x >>
> 32 == x).
>
> (A) What does LLVM assume about "shift width"?

"If op2 is (statically or dynamically) negative or equal to or larger
than the number of bits in op1, the result is undefined."  See
http://llvm.org/docs/LangRef.html#i_shl.  Roughly, that means that
"lshr i32 %x, 32" is allowed to return any arbitrary value.  If you
need consistent behavior, you should explicitly mask the shift amount
in the front-end.

-Eli



More information about the llvm-dev mailing list