diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2010-09-07 05:39:02 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2010-09-07 05:39:02 +0000 |
commit | ad48e01eef196d0a19739c9109c44c4ea251a5db (patch) | |
tree | 6560ad601f795c1b0f7a08e93c448450fc69eb79 /llvm/lib/Support/ConstantRange.cpp | |
parent | 95897c6a3a7e7b9a8ee085948e019df14edb6be6 (diff) | |
download | bcm5719-llvm-ad48e01eef196d0a19739c9109c44c4ea251a5db.tar.gz bcm5719-llvm-ad48e01eef196d0a19739c9109c44c4ea251a5db.zip |
Add completely hokey binary-and and binary-or operations to ConstantRange and
teach LazyValueInfo to use them.
llvm-svn: 113196
Diffstat (limited to 'llvm/lib/Support/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/Support/ConstantRange.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/ConstantRange.cpp b/llvm/lib/Support/ConstantRange.cpp index defb8189b62..c89ec9a2aac 100644 --- a/llvm/lib/Support/ConstantRange.cpp +++ b/llvm/lib/Support/ConstantRange.cpp @@ -608,6 +608,32 @@ ConstantRange::udiv(const ConstantRange &RHS) const { } ConstantRange +ConstantRange::binaryAnd(const ConstantRange &Other) const { + if (isEmptySet() || Other.isEmptySet()) + return ConstantRange(getBitWidth(), /*isFullSet=*/false); + + // TODO: replace this with something less conservative + + APInt umin = APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax()); + if (umin.isAllOnesValue()) + return ConstantRange(getBitWidth(), /*isFullSet=*/true); + return ConstantRange(APInt::getNullValue(getBitWidth()), umin + 1); +} + +ConstantRange +ConstantRange::binaryOr(const ConstantRange &Other) const { + if (isEmptySet() || Other.isEmptySet()) + return ConstantRange(getBitWidth(), /*isFullSet=*/false); + + // TODO: replace this with something less conservative + + APInt umax = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin()); + if (umax.isMinValue()) + return ConstantRange(getBitWidth(), /*isFullSet=*/true); + return ConstantRange(umax, APInt::getNullValue(getBitWidth())); +} + +ConstantRange ConstantRange::shl(const ConstantRange &Other) const { if (isEmptySet() || Other.isEmptySet()) return ConstantRange(getBitWidth(), /*isFullSet=*/false); |