LLVM Discussion Forums

Instruction “AND” is "&&" or "&" in llvm

I’m now going to use LLVM to confuse the instructions in my code. In the path ‘LLVM10 /include/ LLVM /IR/’, there is a file called ‘Instruction.def’ in which the ‘AND’ AND ‘OR’ instructions are defined, so I wonder if ‘AND’ stands for logical OR bitwise operators. Is it “&&” or “&”? I see a comment above the “AND” command definition indicating that “AND” is a logical operator. like this


However, in the path “LLVM10 /include/ LLVM /IR/”, There is a file called “Instructions.h”. It says something like this “/// *p = old & v And,” .The “AND” here may represent the bitwise operator 。So what does “AND” stand for? If it only stands for one of them, how does the other stand for?

Hi,

In LLVM bools are represented as integers of bit width = 1, e.g. i1. Therefore the difference between && and & is only in the types that you provide to your instruction.

For example:

<result> = and i32 %x, %y      ; &
<result> = and i1 %x, %y       ; &&

Hope this solves your question!

I understand. Thanks!

What you’re pointing at in your original post is only bitwise and/or. The comment is either incorrect in the use of “logical” or meant to apply to the first few items and not the whole list.

The logical comparison for integer is icmp