aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorYingwei Zheng <dtcxzyw2333@gmail.com>2023-11-06 19:17:39 +0800
committerGitHub <noreply@github.com>2023-11-06 19:17:39 +0800
commit6f1d3b97c76b26ab68853e28e97368ddddeaa63c (patch)
tree54efce26d0c01018e0963e4ece516b4917b584e3 /llvm/unittests/IR/ConstantRangeTest.cpp
parent333124cfd6dfa413294e80f9be75460b9a9314f9 (diff)
downloadllvm-6f1d3b97c76b26ab68853e28e97368ddddeaa63c.zip
llvm-6f1d3b97c76b26ab68853e28e97368ddddeaa63c.tar.gz
llvm-6f1d3b97c76b26ab68853e28e97368ddddeaa63c.tar.bz2
[ConstantRange] Handle `Intrinsic::cttz` (#67917)
This patch adds support for `Intrinsic::cttz` in ConstantRange. It calculates the range in O(1) with the LCP-based method. Migrated from https://reviews.llvm.org/D153505.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 12facfb..e505af5 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2438,6 +2438,20 @@ TEST_F(ConstantRangeTest, Ctlz) {
});
}
+TEST_F(ConstantRangeTest, Cttz) {
+ TestUnaryOpExhaustive(
+ [](const ConstantRange &CR) { return CR.cttz(); },
+ [](const APInt &N) { return APInt(N.getBitWidth(), N.countr_zero()); });
+
+ TestUnaryOpExhaustive(
+ [](const ConstantRange &CR) { return CR.cttz(/*ZeroIsPoison=*/true); },
+ [](const APInt &N) -> std::optional<APInt> {
+ if (N.isZero())
+ return std::nullopt;
+ return APInt(N.getBitWidth(), N.countr_zero());
+ });
+}
+
TEST_F(ConstantRangeTest, Ctpop) {
TestUnaryOpExhaustive(
[](const ConstantRange &CR) { return CR.ctpop(); },