diff options
author | Dan Gohman <gohman@apple.com> | 2009-12-18 02:58:50 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-12-18 02:58:50 +0000 |
commit | bdc46c6af5ffcf3596a72df75880fe8703436060 (patch) | |
tree | d85a0303352cc1f8bbf93e8e4e1ee1affb7506b7 /lib | |
parent | 2df72c144164cbb06e505f3af506e1bb69053e73 (diff) | |
download | external_llvm-bdc46c6af5ffcf3596a72df75880fe8703436060.zip external_llvm-bdc46c6af5ffcf3596a72df75880fe8703436060.tar.gz external_llvm-bdc46c6af5ffcf3596a72df75880fe8703436060.tar.bz2 |
Add utility routines for creating integer negation operators with NSW set.
Integer negation only overflows with INT_MIN, but that's an important case.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91662 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Constants.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index a62f75b..2507402 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -627,6 +627,12 @@ Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) { return get(std::vector<Constant*>(Vals, Vals+NumVals)); } +Constant* ConstantExpr::getNSWNeg(Constant* C) { + assert(C->getType()->isIntOrIntVector() && + "Cannot NEG a nonintegral value!"); + return getNSWSub(ConstantFP::getZeroValueForNegation(C->getType()), C); +} + Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) { return getTy(C1->getType(), Instruction::Add, C1, C2, OverflowingBinaryOperator::NoSignedWrap); diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index b03ee93..97fec39 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1772,6 +1772,18 @@ BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name, Op->getType(), Name, InsertAtEnd); } +BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name, + Instruction *InsertBefore) { + Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); + return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertBefore); +} + +BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name, + BasicBlock *InsertAtEnd) { + Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); + return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertAtEnd); +} + BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name, Instruction *InsertBefore) { Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); |