diff options
author | Artur Pilipenko <apilipenko@azulsystems.com> | 2016-10-19 14:44:23 +0000 |
---|---|---|
committer | Artur Pilipenko <apilipenko@azulsystems.com> | 2016-10-19 14:44:23 +0000 |
commit | ed84103a1a3d8f81bd662c89607e274682df56a4 (patch) | |
tree | e999cc6251f3c070b2dacd0055e7cc76a335d3ee /llvm/lib/IR/ConstantRange.cpp | |
parent | 2cf1dc2add97f1f54b5561e83183d9b140cf422f (diff) | |
download | bcm5719-llvm-ed84103a1a3d8f81bd662c89607e274682df56a4.tar.gz bcm5719-llvm-ed84103a1a3d8f81bd662c89607e274682df56a4.zip |
Introduce ConstantRange.addWithNoSignedWrap
To be used by upcoming change to IndVarSimplify
Reviewed By: sanjoy
Differential Revision: https://reviews.llvm.org/D25732
llvm-svn: 284597
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index b422eea3692..225eb5e2029 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -674,6 +674,19 @@ ConstantRange::add(const ConstantRange &Other) const { return X; } +ConstantRange ConstantRange::addWithNoSignedWrap(const APInt &Other) const { + // Calculate the subset of this range such that "X + Other" is + // guaranteed not to wrap (overflow) for all X in this subset. + // makeGuaranteedNoWrapRegion will produce an exact NSW range since we are + // passing a single element range. + auto NSWRange = ConstantRange::makeGuaranteedNoWrapRegion(BinaryOperator::Add, + ConstantRange(Other), + OverflowingBinaryOperator::NoSignedWrap); + auto NSWConstrainedRange = intersectWith(NSWRange); + + return NSWConstrainedRange.add(ConstantRange(Other)); +} + ConstantRange ConstantRange::sub(const ConstantRange &Other) const { if (isEmptySet() || Other.isEmptySet()) |