[LLVMdev] Why BinaryOperator::Create requires same argument types for shifts?

Eli Friedman eli.friedman at gmail.com
Fri Aug 26 13:28:38 PDT 2011


On Fri, Aug 26, 2011 at 12:51 PM, Yuri <yuri at rawbw.com> wrote:
> On 08/26/2011 05:32, Stephan Falke wrote:
>> 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



More information about the llvm-dev mailing list