From d122f4b648571867c0f8f72290b6c1a0aac02ebb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 2 Sep 2002 20:49:27 +0000 Subject: [PATCH] Fix bugs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3569 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantRange.cpp | 35 ++++++++++++++++----------- lib/Support/ConstantRange.cpp | 35 ++++++++++++++++----------- lib/VMCore/ConstantRange.cpp | 35 ++++++++++++++++----------- support/lib/Support/ConstantRange.cpp | 35 ++++++++++++++++----------- 4 files changed, 84 insertions(+), 56 deletions(-) diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index 1414b9becac..bda4a83f159 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -142,10 +142,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, const ConstantRange &RHS) { assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); - // Handle common special cases - if (RHS.isEmptySet()) return RHS; - if (RHS.isFullSet()) return LHS; - // Check to see if we overlap on the Left side of RHS... // if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { @@ -178,21 +174,34 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, } } +static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A < *(Constant*)B)->getValue()) + return A; + return B; +} +static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A > *(Constant*)B)->getValue()) + return A; + return B; +} + /// intersect - Return the range that results from the intersection of this /// range with another range. /// ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); + // Handle common special cases + if (isEmptySet() || CR.isFullSet()) return *this; + if (isFullSet() || CR.isEmptySet()) return CR; if (!isWrappedSet()) { if (!CR.isWrappedSet()) { - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); - if ((L < U)->getValue()) // If range isn't empty... - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + if ((*L < *U)->getValue()) // If range isn't empty... + return ConstantRange(L, U); else return ConstantRange(getType(), false); // Otherwise, return empty set } else @@ -202,11 +211,9 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { return intersect1Wrapped(*this, CR); else { // Both ranges are wrapped... - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); - - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); + return ConstantRange(L, U); } } return *this; diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 1414b9becac..bda4a83f159 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -142,10 +142,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, const ConstantRange &RHS) { assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); - // Handle common special cases - if (RHS.isEmptySet()) return RHS; - if (RHS.isFullSet()) return LHS; - // Check to see if we overlap on the Left side of RHS... // if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { @@ -178,21 +174,34 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, } } +static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A < *(Constant*)B)->getValue()) + return A; + return B; +} +static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A > *(Constant*)B)->getValue()) + return A; + return B; +} + /// intersect - Return the range that results from the intersection of this /// range with another range. /// ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); + // Handle common special cases + if (isEmptySet() || CR.isFullSet()) return *this; + if (isFullSet() || CR.isEmptySet()) return CR; if (!isWrappedSet()) { if (!CR.isWrappedSet()) { - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); - if ((L < U)->getValue()) // If range isn't empty... - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + if ((*L < *U)->getValue()) // If range isn't empty... + return ConstantRange(L, U); else return ConstantRange(getType(), false); // Otherwise, return empty set } else @@ -202,11 +211,9 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { return intersect1Wrapped(*this, CR); else { // Both ranges are wrapped... - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); - - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); + return ConstantRange(L, U); } } return *this; diff --git a/lib/VMCore/ConstantRange.cpp b/lib/VMCore/ConstantRange.cpp index 1414b9becac..bda4a83f159 100644 --- a/lib/VMCore/ConstantRange.cpp +++ b/lib/VMCore/ConstantRange.cpp @@ -142,10 +142,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, const ConstantRange &RHS) { assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); - // Handle common special cases - if (RHS.isEmptySet()) return RHS; - if (RHS.isFullSet()) return LHS; - // Check to see if we overlap on the Left side of RHS... // if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { @@ -178,21 +174,34 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, } } +static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A < *(Constant*)B)->getValue()) + return A; + return B; +} +static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A > *(Constant*)B)->getValue()) + return A; + return B; +} + /// intersect - Return the range that results from the intersection of this /// range with another range. /// ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); + // Handle common special cases + if (isEmptySet() || CR.isFullSet()) return *this; + if (isFullSet() || CR.isEmptySet()) return CR; if (!isWrappedSet()) { if (!CR.isWrappedSet()) { - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); - if ((L < U)->getValue()) // If range isn't empty... - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + if ((*L < *U)->getValue()) // If range isn't empty... + return ConstantRange(L, U); else return ConstantRange(getType(), false); // Otherwise, return empty set } else @@ -202,11 +211,9 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { return intersect1Wrapped(*this, CR); else { // Both ranges are wrapped... - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); - - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); + return ConstantRange(L, U); } } return *this; diff --git a/support/lib/Support/ConstantRange.cpp b/support/lib/Support/ConstantRange.cpp index 1414b9becac..bda4a83f159 100644 --- a/support/lib/Support/ConstantRange.cpp +++ b/support/lib/Support/ConstantRange.cpp @@ -142,10 +142,6 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, const ConstantRange &RHS) { assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); - // Handle common special cases - if (RHS.isEmptySet()) return RHS; - if (RHS.isFullSet()) return LHS; - // Check to see if we overlap on the Left side of RHS... // if ((*(Constant*)RHS.getLower() < *(Constant*)LHS.getUpper())->getValue()) { @@ -178,21 +174,34 @@ static ConstantRange intersect1Wrapped(const ConstantRange &LHS, } } +static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A < *(Constant*)B)->getValue()) + return A; + return B; +} +static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B) { + if ((*(Constant*)A > *(Constant*)B)->getValue()) + return A; + return B; +} + /// intersect - Return the range that results from the intersection of this /// range with another range. /// ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { assert(getType() == CR.getType() && "ConstantRange types don't agree!"); + // Handle common special cases + if (isEmptySet() || CR.isFullSet()) return *this; + if (isFullSet() || CR.isEmptySet()) return CR; if (!isWrappedSet()) { if (!CR.isWrappedSet()) { - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); - if ((L < U)->getValue()) // If range isn't empty... - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + if ((*L < *U)->getValue()) // If range isn't empty... + return ConstantRange(L, U); else return ConstantRange(getType(), false); // Otherwise, return empty set } else @@ -202,11 +211,9 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { return intersect1Wrapped(*this, CR); else { // Both ranges are wrapped... - const Constant &L = std::max(*(Constant*)Lower, *(Constant*)CR.Lower); - const Constant &U = std::min(*(Constant*)Upper, *(Constant*)CR.Upper); - - return ConstantRange(cast((Constant*)&L), - cast((Constant*)&U)); + ConstantIntegral *L = Max(Lower, CR.Lower); + ConstantIntegral *U = Min(Upper, CR.Upper); + return ConstantRange(L, U); } } return *this; -- 2.34.1