[llvm] 1c5d636 - [ConstantRangeTest] Add helper to enumerate APInts (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 09:19:00 PST 2021
Author: Nikita Popov
Date: 2021-11-12T18:18:51+01:00
New Revision: 1c5d636af1a7b0786e2d4574cfa469dd27c34be1
URL: https://github.com/llvm/llvm-project/commit/1c5d636af1a7b0786e2d4574cfa469dd27c34be1
DIFF: https://github.com/llvm/llvm-project/commit/1c5d636af1a7b0786e2d4574cfa469dd27c34be1.diff
LOG: [ConstantRangeTest] Add helper to enumerate APInts (NFC)
While ForeachNumInConstantRange(ConstantRange::getFull(Bits))
works, it's somewhat roundabout, and I keep looking for this
function.
Added:
Modified:
llvm/unittests/IR/ConstantRangeTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 17cc29b0b268f..2c54b1c60335c 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -28,6 +28,14 @@ class ConstantRangeTest : public ::testing::Test {
static ConstantRange Wrap;
};
+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;
@@ -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);
});
More information about the llvm-commits
mailing list