diff options
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/DependenceAnalysis.cpp | 22 | ||||
| -rw-r--r-- | llvm/lib/Analysis/HashRecognize.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/Analysis/HeatUtils.cpp | 5 | 
3 files changed, 18 insertions, 14 deletions
| diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index 84ee8c0..11d8294 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -2854,14 +2854,18 @@ bool DependenceInfo::testMIV(const SCEV *Src, const SCEV *Dst,           banerjeeMIVtest(Src, Dst, Loops, Result);  } -// Given a product, e.g., 10*X*Y, returns the first constant operand, -// in this case 10. If there is no constant part, returns std::nullopt. -static std::optional<APInt> getConstantPart(const SCEV *Expr) { +/// Given a SCEVMulExpr, returns its first operand if its first operand is a +/// constant and the product doesn't overflow in a signed sense. Otherwise, +/// returns std::nullopt. For example, given (10 * X * Y)<nsw>, it returns 10. +/// Notably, if it doesn't have nsw, the multiplication may overflow, and if +/// so, it may not a multiple of 10. +static std::optional<APInt> getConstanCoefficient(const SCEV *Expr) {    if (const auto *Constant = dyn_cast<SCEVConstant>(Expr))      return Constant->getAPInt();    if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))      if (const auto *Constant = dyn_cast<SCEVConstant>(Product->getOperand(0))) -      return Constant->getAPInt(); +      if (Product->hasNoSignedWrap()) +        return Constant->getAPInt();    return std::nullopt;  } @@ -2887,7 +2891,7 @@ bool DependenceInfo::accumulateCoefficientsGCD(const SCEV *Expr,    if (AddRec->getLoop() == CurLoop) {      CurLoopCoeff = Step;    } else { -    std::optional<APInt> ConstCoeff = getConstantPart(Step); +    std::optional<APInt> ConstCoeff = getConstanCoefficient(Step);      // If the coefficient is the product of a constant and other stuff, we can      // use the constant in the GCD computation. @@ -2940,7 +2944,7 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,      const SCEV *Coeff = AddRec->getStepRecurrence(*SE);      // If the coefficient is the product of a constant and other stuff,      // we can use the constant in the GCD computation. -    std::optional<APInt> ConstCoeff = getConstantPart(Coeff); +    std::optional<APInt> ConstCoeff = getConstanCoefficient(Coeff);      if (!ConstCoeff)        return false;      RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); @@ -2958,7 +2962,7 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,      const SCEV *Coeff = AddRec->getStepRecurrence(*SE);      // If the coefficient is the product of a constant and other stuff,      // we can use the constant in the GCD computation. -    std::optional<APInt> ConstCoeff = getConstantPart(Coeff); +    std::optional<APInt> ConstCoeff = getConstanCoefficient(Coeff);      if (!ConstCoeff)        return false;      RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); @@ -2979,7 +2983,7 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,        } else if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {          // Search for constant operand to participate in GCD;          // If none found; return false. -        std::optional<APInt> ConstOp = getConstantPart(Product); +        std::optional<APInt> ConstOp = getConstanCoefficient(Product);          if (!ConstOp)            return false;          ExtraGCD = APIntOps::GreatestCommonDivisor(ExtraGCD, ConstOp->abs()); @@ -3032,7 +3036,7 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,      Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff);      // If the coefficient is the product of a constant and other stuff,      // we can use the constant in the GCD computation. -    std::optional<APInt> ConstCoeff = getConstantPart(Delta); +    std::optional<APInt> ConstCoeff = getConstanCoefficient(Delta);      if (!ConstCoeff)        // The difference of the two coefficients might not be a product        // or constant, in which case we give up on this direction. diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp index 4529123..8974ce5 100644 --- a/llvm/lib/Analysis/HashRecognize.cpp +++ b/llvm/lib/Analysis/HashRecognize.cpp @@ -468,8 +468,11 @@ std::variant<PolynomialInfo, StringRef> HashRecognize::recognizeCRC() const {      // Ensure that the PHIs have exactly two uses:      // the bit-shift, and the XOR (or a cast feeding into the XOR). +    // Also ensure that the SimpleRecurrence's evolution doesn't have stray +    // users.      if (!ConditionalRecurrence.Phi->hasNUses(2) || -        !SimpleRecurrence.Phi->hasNUses(2)) +        !SimpleRecurrence.Phi->hasNUses(2) || +        SimpleRecurrence.BO->getUniqueUndroppableUser() != SimpleRecurrence.Phi)        return "Recurrences have stray uses";      // Check that the SelectInst ConditionalRecurrence.Step is conditional on diff --git a/llvm/lib/Analysis/HeatUtils.cpp b/llvm/lib/Analysis/HeatUtils.cpp index a1cc707..08e9428 100644 --- a/llvm/lib/Analysis/HeatUtils.cpp +++ b/llvm/lib/Analysis/HeatUtils.cpp @@ -64,10 +64,7 @@ std::string llvm::getHeatColor(uint64_t Freq, uint64_t MaxFreq) {  }  std::string llvm::getHeatColor(double Percent) { -  if (Percent > 1.0) -    Percent = 1.0; -  if (Percent < 0.0) -    Percent = 0.0; +  Percent = std::clamp(Percent, 0.0, 1.0);    unsigned ColorID = unsigned(round(Percent * (HeatSize - 1.0)));    return HeatPalette[ColorID];  } | 
