aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-03-21 09:25:13 -0700
committerGitHub <noreply@github.com>2024-03-21 09:25:13 -0700
commit12836467b76c56872b4c22a6fd44bcda696ea720 (patch)
treea29a511e2791617a76f0a21c7bb7859bae2962fc /llvm/lib/IR/ConstantRange.cpp
parentd9f0d9a1452ed78e943423c9fbbd63674625f7f5 (diff)
downloadllvm-12836467b76c56872b4c22a6fd44bcda696ea720.zip
llvm-12836467b76c56872b4c22a6fd44bcda696ea720.tar.gz
llvm-12836467b76c56872b4c22a6fd44bcda696ea720.tar.bz2
[ConstantRange] Fix off by 1 bugs in UIToFP and SIToFP handling. (#86041)
We were passing the min and max values of the range to the ConstantRange constructor, but the constructor expects the upper bound to 1 more than the max value so we need to add 1. We also need to use getNonEmpty so that passing 0, 0 to the constructor creates a full range rather than an empty range. And passing smin, smax+1 doesn't cause an assertion. I believe this fixes at least some of the reason #79158 was reverted.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 3394a1e..59e7a9f 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -746,7 +746,7 @@ ConstantRange ConstantRange::castOp(Instruction::CastOps CastOp,
Min = Min.zext(ResultBitWidth);
Max = Max.zext(ResultBitWidth);
}
- return ConstantRange(std::move(Min), std::move(Max));
+ return getNonEmpty(std::move(Min), std::move(Max) + 1);
}
case Instruction::SIToFP: {
// TODO: use input range if available
@@ -757,7 +757,7 @@ ConstantRange ConstantRange::castOp(Instruction::CastOps CastOp,
SMin = SMin.sext(ResultBitWidth);
SMax = SMax.sext(ResultBitWidth);
}
- return ConstantRange(std::move(SMin), std::move(SMax));
+ return getNonEmpty(std::move(SMin), std::move(SMax) + 1);
}
case Instruction::FPTrunc:
case Instruction::FPExt: