aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-11-12 18:17:27 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-11-12 18:18:51 +0100
commit1c5d636af1a7b0786e2d4574cfa469dd27c34be1 (patch)
treead7f0f0676f6adb0a9b248e063761d0daf8ecdb0 /llvm/unittests/IR/ConstantRangeTest.cpp
parent52a3ed5b93ca9aba042d87e2bb697bf0dda2e43c (diff)
downloadllvm-1c5d636af1a7b0786e2d4574cfa469dd27c34be1.zip
llvm-1c5d636af1a7b0786e2d4574cfa469dd27c34be1.tar.gz
llvm-1c5d636af1a7b0786e2d4574cfa469dd27c34be1.tar.bz2
[ConstantRangeTest] Add helper to enumerate APInts (NFC)
While ForeachNumInConstantRange(ConstantRange::getFull(Bits)) works, it's somewhat roundabout, and I keep looking for this function.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 17cc29b..2c54b1c6 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -29,6 +29,14 @@ protected:
};
template<typename Fn>
+static void EnumerateAPInts(unsigned Bits, Fn TestFn) {
+ APInt N(Bits, 0);
+ do {
+ TestFn(N);
+ } while (++N != 0);
+}
+
+template<typename Fn>
static void EnumerateConstantRanges(unsigned Bits, Fn TestFn) {
unsigned Max = 1 << Bits;
for (unsigned Lo = 0; Lo < Max; Lo++) {
@@ -1824,8 +1832,7 @@ void TestNoWrapRegionExhaustive(Instruction::BinaryOps BinOp,
ConstantRange NoWrap =
ConstantRange::makeGuaranteedNoWrapRegion(BinOp, CR, NoWrapKind);
- ConstantRange Full = ConstantRange::getFull(Bits);
- ForeachNumInConstantRange(Full, [&](const APInt &N1) {
+ EnumerateAPInts(Bits, [&](const APInt &N1) {
bool NoOverflow = true;
bool Overflow = true;
ForeachNumInConstantRange(CR, [&](const APInt &N2) {
@@ -1986,17 +1993,18 @@ TEST(ConstantRange, GetEquivalentICmp) {
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
EXPECT_EQ(RHS, APInt(32, -1));
- EnumerateConstantRanges(4, [](const ConstantRange &CR) {
+ unsigned Bits = 4;
+ EnumerateConstantRanges(Bits, [Bits](const ConstantRange &CR) {
CmpInst::Predicate Pred;
APInt RHS, Offset;
CR.getEquivalentICmp(Pred, RHS, Offset);
- ForeachNumInConstantRange(ConstantRange::getFull(4), [&](const APInt &N) {
+ EnumerateAPInts(Bits, [&](const APInt &N) {
bool Result = ICmpInst::compare(N + Offset, RHS, Pred);
EXPECT_EQ(CR.contains(N), Result);
});
if (CR.getEquivalentICmp(Pred, RHS)) {
- ForeachNumInConstantRange(ConstantRange::getFull(4), [&](const APInt &N) {
+ EnumerateAPInts(Bits, [&](const APInt &N) {
bool Result = ICmpInst::compare(N, RHS, Pred);
EXPECT_EQ(CR.contains(N), Result);
});