diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-30 22:47:33 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-30 22:49:28 +0200 |
commit | 94f8120cb9d368602df5aefa32211e001338e296 (patch) | |
tree | c2ce28a5ffb5c5a0c56b965eac5aa69029b7c600 /llvm/lib/IR/ConstantRange.cpp | |
parent | 8c1a31d83313e4d43509177193f1de14cf897c05 (diff) | |
download | llvm-94f8120cb9d368602df5aefa32211e001338e296.zip llvm-94f8120cb9d368602df5aefa32211e001338e296.tar.gz llvm-94f8120cb9d368602df5aefa32211e001338e296.tar.bz2 |
[ConstantRange] Support abs with poison flag
This just adds the ConstantRange support, including exhaustive
testing. It's not wired up to the IR intrinsic flag yet.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index d379140..6e0b5a0 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -1464,7 +1464,7 @@ ConstantRange ConstantRange::inverse() const { return ConstantRange(Upper, Lower); } -ConstantRange ConstantRange::abs() const { +ConstantRange ConstantRange::abs(bool IntMinIsPoison) const { if (isEmptySet()) return getEmpty(); @@ -1476,12 +1476,23 @@ ConstantRange ConstantRange::abs() const { else Lo = APIntOps::umin(Lower, -Upper + 1); - // SignedMin is included in the result range. - return ConstantRange(Lo, APInt::getSignedMinValue(getBitWidth()) + 1); + // If SignedMin is not poison, then it is included in the result range. + if (IntMinIsPoison) + return ConstantRange(Lo, APInt::getSignedMinValue(getBitWidth())); + else + return ConstantRange(Lo, APInt::getSignedMinValue(getBitWidth()) + 1); } APInt SMin = getSignedMin(), SMax = getSignedMax(); + // Skip SignedMin if it is poison. + if (IntMinIsPoison && SMin.isMinSignedValue()) { + // The range may become empty if it *only* contains SignedMin. + if (SMax.isMinSignedValue()) + return getEmpty(); + ++SMin; + } + // All non-negative. if (SMin.isNonNegative()) return *this; |