Why there is no unary operator in LLVM?

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](http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a073c092ce74a122e898e435e60e84599) [BinaryOperator](http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html) *[BinaryOperator::CreateNeg](http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a073c092ce74a122e898e435e60e84599)([Value](http://llvm.org/doxygen/classllvm_1_1Value.html) *Op, const [Twine](http://llvm.org/doxygen/classllvm_1_1Twine.html) &Name,
01824                                           [BasicBlock](http://llvm.org/doxygen/classllvm_1_1BasicBlock.html) *InsertAtEnd) {
01825   [Value](http://llvm.org/doxygen/classllvm_1_1Value.html) *zero = [ConstantFP::getZeroValueForNegation](http://llvm.org/doxygen/classllvm_1_1ConstantFP.html#ab4d218c572245abd0b1c895d603cba36)(Op->[getType](http://llvm.org/doxygen/classllvm_1_1Value.html#a0cf3748dba54f931bb1241ae4adc76bc)());
01826   return new [BinaryOperator](http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#acf242c32d995c5276931f545aa2bdd9c)(Instruction::Sub,
01827                             zero, Op,
01828                             Op->[getType](http://llvm.org/doxygen/classllvm_1_1Value.html#a0cf3748dba54f931bb1241ae4adc76bc)(), [Name](http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a274586caf47dcc28ed878ad21af28152), 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?

Thanks!

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