[LLVMdev] [RFC] Proposal to make LLVM-IR endian agnostic

Török Edwin edwintorok at gmail.com
Tue Oct 4 00:51:33 PDT 2011


On 10/04/2011 10:28 AM, Duncan Sands wrote:
> Hi Edwin,
> 
>> FWIW here is another way to do it (which is approximately what ClamAV does currently) by introducing just one intrinsic:
>> declare i1 @llvm.is_bigendian()
> 
> why is an intrinsic needed? 

You are right its not.

 It is easy to write a small LLVM IR function
> that computes this.  For example:
> 
> define i1 @is_big_endian() {
>    %ip = alloca i16
>    store i16 1, i16* %ip
>    %cp = bitcast i16* %ip to i8*
>    %c = load i8* %cp
>    %r = icmp eq i8 %c, 0
>    ret i1 %r
> }
> 

Indeed that can be optimized away, but it needs inlining to be run to make the callers completely go away.

Best regards,
--Edwin



More information about the llvm-dev mailing list