Why BinaryOperator::Create requires same argument types for shifts?

I get an assert @ Instructions.cpp:1774 when Op=llvm::Instruction::Shl.
Should this assert avoid shift operations?

Yuri

Hi Yuri,

As stated in LLVM's language reference manual (http://llvm.org/docs/LangRef.html#i_shl), both arguments for a shl need to have the same type.

What exactly are you trying to do?

--Stephan

In my case, original types were uint8 (value) and uint32 (shift)
llvm lacks unsigned types which made it S1=i8 and S2=i32. It's technically nothing wrong with such combination, and code works fine until I ran debug llvm for some other reason and this assert showed up.

So if I need to shift signed int8 with unsigned uint32, I have to first truncate shift to uint8, with understanding that uint8 will become int8 because llvm lacks unsignedness?
I think such requirement is redundant and you should make an exception in shift operator definitions to allow for any combination of numeric arguments. It forces to create an extra trunc/expand operator without the real need.

Yuri

As stated in LLVM's language reference manual
(http://llvm.org/docs/LangRef.html#i_shl), both arguments for a shl need
to have the same type.

In my case, original types were uint8 (value) and uint32 (shift)
llvm lacks unsigned types which made it S1=i8 and S2=i32. It's
technically nothing wrong with such combination, and code works fine
until I ran debug llvm for some other reason and this assert showed up.

So if I need to shift signed int8 with unsigned uint32, I have to first
truncate shift to uint8, with understanding that uint8 will become int8
because llvm lacks unsignedness?

(LLVM integer types aren't signed or unsigned; the operations on them are.)

I think such requirement is redundant and you should make an exception
in shift operator definitions to allow for any combination of numeric
arguments. It forces to create an extra trunc/expand operator without
the real need.

Every BinaryOperator has two operands of the same type; it isn't worth
the mess to change that...

-Eli