[PATCH] D60662: [ConstantRange] Simplify unittests after getSetSize was removed
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 14 01:15:06 PDT 2019
MaskRay created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
MaskRay added a reviewer: lebedev.ri.
Repository:
rL LLVM
https://reviews.llvm.org/D60662
Files:
unittests/IR/ConstantRangeTest.cpp
Index: unittests/IR/ConstantRangeTest.cpp
===================================================================
--- unittests/IR/ConstantRangeTest.cpp
+++ unittests/IR/ConstantRangeTest.cpp
@@ -51,17 +51,12 @@
template<typename Fn>
static void ForeachNumInConstantRange(const ConstantRange &CR, Fn TestFn) {
- if (CR.isFullSet()) {
- for (APInt N = APInt::getNullValue(CR.getBitWidth());;) {
+ if (!CR.isEmptySet())
+ for (APInt N = CR.getLower();;) {
TestFn(N);
- if (N == APInt::getAllOnesValue(CR.getBitWidth()))
+ if (++N == CR.getUpper())
break;
- ++N;
}
- return;
- }
- for (APInt N = CR.getLower(); N != CR.getUpper(); ++N)
- TestFn(N);
}
ConstantRange ConstantRangeTest::Full(16, true);
@@ -1465,31 +1460,27 @@
unsigned Bits = 4;
EnumerateTwoConstantRanges(Bits, [=](const ConstantRange &CR1,
const ConstantRange &CR2) {
- unsigned Size1 = CR1.isFullSet()
- ? 1u << CR1.getBitWidth()
- : (CR1.getUpper() - CR1.getLower()).getZExtValue();
- unsigned Size2 = CR2.isFullSet()
- ? 1u << CR2.getBitWidth()
- : (CR2.getUpper() - CR2.getLower()).getZExtValue();
-
// Loop over all N1 in CR1 and N2 in CR2 and check whether any of the
// operations have overflow / have no overflow. These loops are based
// on Size1/Size2 to properly handle empty/full ranges.
bool RangeHasOverflow = false;
bool RangeHasNoOverflow = false;
- APInt N1 = CR1.getLower();
- for (unsigned I1 = 0; I1 < Size1; ++I1, ++N1) {
- APInt N2 = CR2.getLower();
- for (unsigned I2 = 0; I2 < Size2; ++I2, ++N2) {
- assert(CR1.contains(N1));
- assert(CR2.contains(N2));
+ if (!CR1.isEmptySet() && !CR2.isEmptySet())
+ for (APInt N1 = CR1.getLower();;) {
+ for (APInt N2 = CR2.getLower();;) {
+ assert(CR1.contains(N1));
+ assert(CR2.contains(N2));
- if (OverflowFn(N1, N2))
- RangeHasOverflow = true;
- else
- RangeHasNoOverflow = true;
+ if (OverflowFn(N1, N2))
+ RangeHasOverflow = true;
+ else
+ RangeHasNoOverflow = true;
+ if (++N2 == CR2.getUpper())
+ break;
+ }
+ if (++N1 == CR1.getUpper())
+ break;
}
- }
ConstantRange::OverflowResult OR = MayOverflowFn(CR1, CR2);
switch (OR) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60662.195050.patch
Type: text/x-patch
Size: 2490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190414/366c512e/attachment.bin>
More information about the llvm-commits
mailing list