aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2020-03-24 12:47:24 +0000
committerFlorian Hahn <flo@fhahn.com>2020-03-24 12:59:50 +0000
commit7caba33907afce839c092661e20fdfd51b08e7d0 (patch)
treea3823693a81ccd4fe2d4ec5fee6cdd148d3f71ca /llvm/lib/IR/ConstantRange.cpp
parent0b5998213415147d901d394cfc47d7daedacc3cf (diff)
downloadllvm-7caba33907afce839c092661e20fdfd51b08e7d0.zip
llvm-7caba33907afce839c092661e20fdfd51b08e7d0.tar.gz
llvm-7caba33907afce839c092661e20fdfd51b08e7d0.tar.bz2
[ConstantRange] Add initial support for binaryXor.
The initial implementation just delegates to APInt's implementation of XOR for single element ranges and conservatively returns the full set otherwise. Reviewers: nikic, spatel, lebedev.ri Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D76453
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 3d25cb5..b8c5753 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -802,6 +802,8 @@ ConstantRange ConstantRange::binaryOp(Instruction::BinaryOps BinOp,
return binaryAnd(Other);
case Instruction::Or:
return binaryOr(Other);
+ case Instruction::Xor:
+ return binaryXor(Other);
// Note: floating point operations applied to abstract ranges are just
// ideal integer operations with a lossy representation
case Instruction::FAdd:
@@ -1211,6 +1213,18 @@ ConstantRange::binaryOr(const ConstantRange &Other) const {
return getNonEmpty(std::move(umax), APInt::getNullValue(getBitWidth()));
}
+ConstantRange ConstantRange::binaryXor(const ConstantRange &Other) const {
+ if (isEmptySet() || Other.isEmptySet())
+ return getEmpty();
+
+ // Use APInt's implementation of XOR for single element ranges.
+ if (isSingleElement() && Other.isSingleElement())
+ return {*getSingleElement() ^ *Other.getSingleElement()};
+
+ // TODO: replace this with something less conservative
+ return getFull();
+}
+
ConstantRange
ConstantRange::shl(const ConstantRange &Other) const {
if (isEmptySet() || Other.isEmptySet())