diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-16 18:55:16 +0000 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-16 18:55:16 +0000 |
| commit | 79dffc67b50e55e3294a6d0391e97b06c7030071 (patch) | |
| tree | 13b603c1b5cd4652a95be892ece9d8b9f2741a19 /llvm/lib/IR | |
| parent | d8f776af6ed999fa621062b6c8b92d1e45e57516 (diff) | |
| download | bcm5719-llvm-79dffc67b50e55e3294a6d0391e97b06c7030071.tar.gz bcm5719-llvm-79dffc67b50e55e3294a6d0391e97b06c7030071.zip | |
[IR] Add WithOverflowInst class
This adds a WithOverflowInst class with a few helper methods to get
the underlying binop, signedness and nowrap type and makes use of it
where sensible. There will be two more uses in D60650/D60656.
The refactorings are all NFC, though I left some TODOs where things
could be improved. In particular we have two places where add/sub are
handled but mul isn't.
Differential Revision: https://reviews.llvm.org/D60668
llvm-svn: 358512
Diffstat (limited to 'llvm/lib/IR')
| -rw-r--r-- | llvm/lib/IR/IntrinsicInst.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index 8d371aabb21..2e2da0edb08 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -21,6 +21,7 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Operator.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" @@ -168,3 +169,36 @@ bool ConstrainedFPIntrinsic::isTernaryOp() const { } } +Instruction::BinaryOps WithOverflowInst::getBinaryOp() const { + switch (getIntrinsicID()) { + case Intrinsic::uadd_with_overflow: + case Intrinsic::sadd_with_overflow: + return Instruction::Add; + case Intrinsic::usub_with_overflow: + case Intrinsic::ssub_with_overflow: + return Instruction::Sub; + case Intrinsic::umul_with_overflow: + case Intrinsic::smul_with_overflow: + return Instruction::Mul; + default: + llvm_unreachable("Invalid intrinsic"); + } +} + +bool WithOverflowInst::isSigned() const { + switch (getIntrinsicID()) { + case Intrinsic::sadd_with_overflow: + case Intrinsic::ssub_with_overflow: + case Intrinsic::smul_with_overflow: + return true; + default: + return false; + } +} + +unsigned WithOverflowInst::getNoWrapKind() const { + if (isSigned()) + return OverflowingBinaryOperator::NoSignedWrap; + else + return OverflowingBinaryOperator::NoUnsignedWrap; +} |

