[LLVMdev] Why there is no unary operator in LLVM?
Eli Friedman
eli.friedman at gmail.com
Thu Nov 3 09:48:52 PDT 2011
On Thu, Nov 3, 2011 at 3:45 AM, Fan Dawei <fandawei.s at gmail.com> wrote:
> Hi llvmdev,
>
> I've noticed that there is no unary operator in LLVM. For unary operator
> such as Neg or Or operator, the IR builder just creates a binary operation
> with one dummy operand,
>
> 01823 BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine
> &Name,
> 01824 BasicBlock *InsertAtEnd) {
> 01825 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
> 01826 return new BinaryOperator(Instruction::Sub,
> 01827 zero, Op,
> 01828 Op->getType(), Name, InsertAtEnd);
>
>
> However, I think it's more natural to describe this as unary operation, and
> may bring benefits to the optimiser and code generator.
>
> Can anyone tell me the reason?
We describe it as a binary operation simply to reduce the number of
instructions in the IR. There are helper functions for things which
are really looking for unary not etc.
-Eli
More information about the llvm-dev
mailing list