diff options
author | Ramkumar Ramachandra <ramkumar.ramachandra@codasip.com> | 2025-06-28 11:43:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-28 11:43:10 +0100 |
commit | 5ea29f77b9f809a3a33de72033e21225ec292170 (patch) | |
tree | 4c09911cdb5431f1e003e6a471e97e951ead6f15 /llvm/lib/Analysis/DependenceAnalysis.cpp | |
parent | 04cd0f270227820c453ddf1a13c3c55145852e11 (diff) | |
download | llvm-5ea29f77b9f809a3a33de72033e21225ec292170.zip llvm-5ea29f77b9f809a3a33de72033e21225ec292170.tar.gz llvm-5ea29f77b9f809a3a33de72033e21225ec292170.tar.bz2 |
[DA] Let getConstantPart return optional APInt (NFC) (#146135)
To use the result of an SCEVConstant, we need to extract the APInt,
which callers anyway do.
Diffstat (limited to 'llvm/lib/Analysis/DependenceAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/DependenceAnalysis.cpp | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index c1b1d00..b93f700 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -2372,20 +2372,17 @@ 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 NULL. -static -const SCEVConstant *getConstantPart(const SCEV *Expr) { +// in this case 10. If there is no constant part, returns std::nullopt. +static std::optional<APInt> getConstantPart(const SCEV *Expr) { if (const auto *Constant = dyn_cast<SCEVConstant>(Expr)) - return Constant; - else if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr)) + return Constant->getAPInt(); + if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr)) if (const auto *Constant = dyn_cast<SCEVConstant>(Product->getOperand(0))) - return Constant; - return nullptr; + return Constant->getAPInt(); + return std::nullopt; } - //===----------------------------------------------------------------------===// // gcdMIVtest - // Tests an MIV subscript pair for dependence. @@ -2421,11 +2418,10 @@ 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. - const auto *Constant = getConstantPart(Coeff); - if (!Constant) + std::optional<APInt> ConstCoeff = getConstantPart(Coeff); + if (!ConstCoeff) return false; - APInt ConstCoeff = Constant->getAPInt(); - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); + RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); Coefficients = AddRec->getStart(); } const SCEV *SrcConst = Coefficients; @@ -2440,11 +2436,10 @@ 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. - const auto *Constant = getConstantPart(Coeff); - if (!Constant) + std::optional<APInt> ConstCoeff = getConstantPart(Coeff); + if (!ConstCoeff) return false; - APInt ConstCoeff = Constant->getAPInt(); - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); + RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); Coefficients = AddRec->getStart(); } const SCEV *DstConst = Coefficients; @@ -2463,12 +2458,10 @@ 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. - const SCEVConstant *ConstOp = getConstantPart(Product); + std::optional<APInt> ConstOp = getConstantPart(Product); if (!ConstOp) return false; - APInt ConstOpValue = ConstOp->getAPInt(); - ExtraGCD = APIntOps::GreatestCommonDivisor(ExtraGCD, - ConstOpValue.abs()); + ExtraGCD = APIntOps::GreatestCommonDivisor(ExtraGCD, ConstOp->abs()); } else return false; @@ -2520,11 +2513,11 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst, else { // If the coefficient is the product of a constant and other stuff, // we can use the constant in the GCD computation. - Constant = getConstantPart(Coeff); - if (!Constant) + std::optional<APInt> ConstCoeff = getConstantPart(Coeff); + if (!ConstCoeff) return false; - APInt ConstCoeff = Constant->getAPInt(); - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); + RunningGCD = + APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); } Inner = AddRec->getStart(); } @@ -2537,24 +2530,23 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst, else { // If the coefficient is the product of a constant and other stuff, // we can use the constant in the GCD computation. - Constant = getConstantPart(Coeff); - if (!Constant) + std::optional<APInt> ConstCoeff = getConstantPart(Coeff); + if (!ConstCoeff) return false; - APInt ConstCoeff = Constant->getAPInt(); - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); + RunningGCD = + APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); } Inner = AddRec->getStart(); } 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. - Constant = getConstantPart(Delta); - if (!Constant) + std::optional<APInt> ConstCoeff = getConstantPart(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. continue; - APInt ConstCoeff = Constant->getAPInt(); - RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); + RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff->abs()); LLVM_DEBUG(dbgs() << "\tRunningGCD = " << RunningGCD << "\n"); if (RunningGCD != 0) { Remainder = ConstDelta.srem(RunningGCD); |