llvm.org GIT mirror llvm / faf8d94
[ConstantRange] Rename isWrappedSet() to isUpperWrapped() Split out from D59749. The current implementation of isWrappedSet() doesn't do what it says on the tin, and treats ranges like [X, Max] as wrapping, because they are represented as [X, 0) when using half-inclusive ranges. This also makes it inconsistent with the semantics of isSignWrappedSet(). This patch renames isWrappedSet() to isUpperWrapped(), in preparation for the introduction of a new isWrappedSet() method with corrected behavior. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357107 91177308-0d34-0410-b5e6-96231b3b80d8 Nikita Popov 6 months ago
4 changed file(s) with 29 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
162162 /// Return true if this set contains no members.
163163 bool isEmptySet() const;
164164
165 /// Return true if this set wraps around the top of the range.
166 /// For example: [100, 8).
167 bool isWrappedSet() const;
165 /// Return true if the exclusive upper bound wraps around the unsigned
166 /// domain. Special cases:
167 /// * Empty set: Not wrapped.
168 /// * Full set: Not wrapped.
169 /// * [X, 0): Wrapped.
170 bool isUpperWrapped() const;
168171
169172 /// Return true if this set wraps around the signed domain. Special cases:
170173 /// * Empty set: Not wrapped.
83458345 return Op;
83468346
83478347 ConstantRange CR = getConstantRangeFromMetadata(*Range);
8348 if (CR.isFullSet() || CR.isEmptySet() || CR.isWrappedSet())
8348 if (CR.isFullSet() || CR.isEmptySet() || CR.isUpperWrapped())
83498349 return Op;
83508350
83518351 APInt Lo = CR.getUnsignedMin();
343343 return Lower == Upper && Lower.isMinValue();
344344 }
345345
346 bool ConstantRange::isWrappedSet() const {
346 bool ConstantRange::isUpperWrapped() const {
347347 return Lower.ugt(Upper);
348348 }
349349
381381 }
382382
383383 APInt ConstantRange::getUnsignedMax() const {
384 if (isFullSet() || isWrappedSet())
384 if (isFullSet() || isUpperWrapped())
385385 return APInt::getMaxValue(getBitWidth());
386386 return getUpper() - 1;
387387 }
388388
389389 APInt ConstantRange::getUnsignedMin() const {
390 if (isFullSet() || (isWrappedSet() && !getUpper().isNullValue()))
390 if (isFullSet() || (isUpperWrapped() && !getUpper().isNullValue()))
391391 return APInt::getMinValue(getBitWidth());
392392 return getLower();
393393 }
408408 if (Lower == Upper)
409409 return isFullSet();
410410
411 if (!isWrappedSet())
411 if (!isUpperWrapped())
412412 return Lower.ule(V) && V.ult(Upper);
413413 return Lower.ule(V) || V.ult(Upper);
414414 }
417417 if (isFullSet() || Other.isEmptySet()) return true;
418418 if (isEmptySet() || Other.isFullSet()) return false;
419419
420 if (!isWrappedSet()) {
421 if (Other.isWrappedSet())
420 if (!isUpperWrapped()) {
421 if (Other.isUpperWrapped())
422422 return false;
423423
424424 return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper);
425425 }
426426
427 if (!Other.isWrappedSet())
427 if (!Other.isUpperWrapped())
428428 return Other.getUpper().ule(Upper) ||
429429 Lower.ule(Other.getLower());
430430
451451 if ( isEmptySet() || CR.isFullSet()) return *this;
452452 if (CR.isEmptySet() || isFullSet()) return CR;
453453
454 if (!isWrappedSet() && CR.isWrappedSet())
454 if (!isUpperWrapped() && CR.isUpperWrapped())
455455 return CR.intersectWith(*this);
456456
457 if (!isWrappedSet() && !CR.isWrappedSet()) {
457 if (!isUpperWrapped() && !CR.isUpperWrapped()) {
458458 if (Lower.ult(CR.Lower)) {
459459 if (Upper.ule(CR.Lower))
460460 return getEmpty();
473473 return getEmpty();
474474 }
475475
476 if (isWrappedSet() && !CR.isWrappedSet()) {
476 if (isUpperWrapped() && !CR.isUpperWrapped()) {
477477 if (CR.Lower.ult(Upper)) {
478478 if (CR.Upper.ult(Upper))
479479 return CR;
524524 if ( isFullSet() || CR.isEmptySet()) return *this;
525525 if (CR.isFullSet() || isEmptySet()) return CR;
526526
527 if (!isWrappedSet() && CR.isWrappedSet()) return CR.unionWith(*this);
528
529 if (!isWrappedSet() && !CR.isWrappedSet()) {
527 if (!isUpperWrapped() && CR.isUpperWrapped()) return CR.unionWith(*this);
528
529 if (!isUpperWrapped() && !CR.isUpperWrapped()) {
530530 if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) {
531531 // If the two ranges are disjoint, find the smaller gap and bridge it.
532532 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
544544 return ConstantRange(std::move(L), std::move(U));
545545 }
546546
547 if (!CR.isWrappedSet()) {
547 if (!CR.isUpperWrapped()) {
548548 // ------U L----- and ------U L----- : this
549549 // L--U L--U : CR
550550 if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))
636636
637637 unsigned SrcTySize = getBitWidth();
638638 assert(SrcTySize < DstTySize && "Not a value extension");
639 if (isFullSet() || isWrappedSet()) {
639 if (isFullSet() || isUpperWrapped()) {
640640 // Change into [0, 1 << src bit width)
641641 APInt LowerExt(DstTySize, 0);
642642 if (!Upper) // special case: [X, 0) -- not really wrapping around
679679 // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue]
680680 // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
681681 // then we do the union with [MaxValue, Upper)
682 if (isWrappedSet()) {
682 if (isUpperWrapped()) {
683683 // If Upper is greater than or equal to MaxValue(DstTy), it covers the whole
684684 // truncated range.
685685 if (Upper.getActiveBits() > DstTySize ||
858858 // from one positive number to another which is as good as we can generate.
859859 // In this case, skip the extra work of generating signed ranges which aren't
860860 // going to be better than this range.
861 if (!UR.isWrappedSet() &&
861 if (!UR.isUpperWrapped() &&
862862 (UR.getUpper().isNonNegative() || UR.getUpper().isMinSignedValue()))
863863 return UR;
864864
3434 EXPECT_TRUE(Full.isFullSet());
3535 EXPECT_FALSE(Full.isEmptySet());
3636 EXPECT_TRUE(Full.inverse().isEmptySet());
37 EXPECT_FALSE(Full.isWrappedSet());
37 EXPECT_FALSE(Full.isUpperWrapped());
3838 EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
3939 EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
4040 EXPECT_TRUE(Full.contains(APInt(16, 0xa)));
4444 EXPECT_FALSE(Empty.isFullSet());
4545 EXPECT_TRUE(Empty.isEmptySet());
4646 EXPECT_TRUE(Empty.inverse().isFullSet());
47 EXPECT_FALSE(Empty.isWrappedSet());
47 EXPECT_FALSE(Empty.isUpperWrapped());
4848 EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
4949 EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
5050 EXPECT_FALSE(Empty.contains(APInt(16, 0xa)));
5353
5454 EXPECT_FALSE(One.isFullSet());
5555 EXPECT_FALSE(One.isEmptySet());
56 EXPECT_FALSE(One.isWrappedSet());
56 EXPECT_FALSE(One.isUpperWrapped());
5757 EXPECT_FALSE(One.contains(APInt(16, 0x0)));
5858 EXPECT_FALSE(One.contains(APInt(16, 0x9)));
5959 EXPECT_TRUE(One.contains(APInt(16, 0xa)));
6363
6464 EXPECT_FALSE(Some.isFullSet());
6565 EXPECT_FALSE(Some.isEmptySet());
66 EXPECT_FALSE(Some.isWrappedSet());
66 EXPECT_FALSE(Some.isUpperWrapped());
6767 EXPECT_FALSE(Some.contains(APInt(16, 0x0)));
6868 EXPECT_FALSE(Some.contains(APInt(16, 0x9)));
6969 EXPECT_TRUE(Some.contains(APInt(16, 0xa)));
7272
7373 EXPECT_FALSE(Wrap.isFullSet());
7474 EXPECT_FALSE(Wrap.isEmptySet());
75 EXPECT_TRUE(Wrap.isWrappedSet());
75 EXPECT_TRUE(Wrap.isUpperWrapped());
7676 EXPECT_TRUE(Wrap.contains(APInt(16, 0x0)));
7777 EXPECT_TRUE(Wrap.contains(APInt(16, 0x9)));
7878 EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));