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

Duncan Sands baldrick at free.fr
Tue Oct 4 00:28:18 PDT 2011

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?  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

Ciao, Duncan.

More information about the llvm-dev mailing list