aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-07-01 15:43:27 +0200
committerNikita Popov <npopov@redhat.com>2022-07-01 15:44:59 +0200
commitba1e04b9668b3502362f2ee36232f5f56e72b4e2 (patch)
tree83e1124f5acb76b877f878b3d8222b39c1a5a2b4 /llvm/lib/IR/ConstantRange.cpp
parent5166345f50412f1a380948c18809545c4b7a9bd3 (diff)
downloadllvm-ba1e04b9668b3502362f2ee36232f5f56e72b4e2.zip
llvm-ba1e04b9668b3502362f2ee36232f5f56e72b4e2.tar.gz
llvm-ba1e04b9668b3502362f2ee36232f5f56e72b4e2.tar.bz2
[ConstantRange] Fix sdiv() with one bit values (PR56333)
Signed one bit values can only be -1 or 0, not positive. The code was interpreting the 1 as -1 and intersecting with a full range rather than an empty one. Fixes https://github.com/llvm/llvm-project/issues/56333.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index be6386c..9d23910 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1238,7 +1238,10 @@ ConstantRange ConstantRange::sdiv(const ConstantRange &RHS) const {
// separately by combining division results with the appropriate signs.
APInt Zero = APInt::getZero(getBitWidth());
APInt SignedMin = APInt::getSignedMinValue(getBitWidth());
- ConstantRange PosFilter(APInt(getBitWidth(), 1), SignedMin);
+ // There are no positive 1-bit values. The 1 would get interpreted as -1.
+ ConstantRange PosFilter =
+ getBitWidth() == 1 ? getEmpty()
+ : ConstantRange(APInt(getBitWidth(), 1), SignedMin);
ConstantRange NegFilter(SignedMin, Zero);
ConstantRange PosL = intersectWith(PosFilter);
ConstantRange NegL = intersectWith(NegFilter);