@@ -2375,17 +2375,15 @@ bool DependenceInfo::testMIV(const SCEV *Src, const SCEV *Dst,
23752375
23762376// Given a product, e.g., 10*X*Y, returns the first constant operand,
23772377// in this case 10. If there is no constant part, returns NULL.
2378- static
2379- const SCEVConstant *getConstantPart (const SCEV *Expr) {
2378+ static std::optional<APInt> getConstantPart (const SCEV *Expr) {
23802379 if (const auto *Constant = dyn_cast<SCEVConstant>(Expr))
2381- return Constant;
2382- else if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2380+ return Constant-> getAPInt () ;
2381+ if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
23832382 if (const auto *Constant = dyn_cast<SCEVConstant>(Product->getOperand (0 )))
2384- return Constant;
2385- return nullptr ;
2383+ return Constant-> getAPInt () ;
2384+ return std:: nullopt ;
23862385}
23872386
2388-
23892387// ===----------------------------------------------------------------------===//
23902388// gcdMIVtest -
23912389// Tests an MIV subscript pair for dependence.
@@ -2421,11 +2419,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
24212419 const SCEV *Coeff = AddRec->getStepRecurrence (*SE);
24222420 // If the coefficient is the product of a constant and other stuff,
24232421 // we can use the constant in the GCD computation.
2424- const auto *Constant = getConstantPart (Coeff);
2425- if (!Constant )
2422+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2423+ if (!ConstCoeff )
24262424 return false ;
2427- APInt ConstCoeff = Constant->getAPInt ();
2428- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2425+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
24292426 Coefficients = AddRec->getStart ();
24302427 }
24312428 const SCEV *SrcConst = Coefficients;
@@ -2440,11 +2437,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
24402437 const SCEV *Coeff = AddRec->getStepRecurrence (*SE);
24412438 // If the coefficient is the product of a constant and other stuff,
24422439 // we can use the constant in the GCD computation.
2443- const auto *Constant = getConstantPart (Coeff);
2444- if (!Constant )
2440+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2441+ if (!ConstCoeff )
24452442 return false ;
2446- APInt ConstCoeff = Constant->getAPInt ();
2447- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2443+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
24482444 Coefficients = AddRec->getStart ();
24492445 }
24502446 const SCEV *DstConst = Coefficients;
@@ -2463,12 +2459,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
24632459 else if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
24642460 // Search for constant operand to participate in GCD;
24652461 // If none found; return false.
2466- const SCEVConstant * ConstOp = getConstantPart (Product);
2462+ std::optional<APInt> ConstOp = getConstantPart (Product);
24672463 if (!ConstOp)
24682464 return false ;
2469- APInt ConstOpValue = ConstOp->getAPInt ();
2470- ExtraGCD = APIntOps::GreatestCommonDivisor (ExtraGCD,
2471- ConstOpValue.abs ());
2465+ ExtraGCD = APIntOps::GreatestCommonDivisor (ExtraGCD, ConstOp->abs ());
24722466 }
24732467 else
24742468 return false ;
@@ -2520,11 +2514,11 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
25202514 else {
25212515 // If the coefficient is the product of a constant and other stuff,
25222516 // we can use the constant in the GCD computation.
2523- Constant = getConstantPart (Coeff);
2524- if (!Constant )
2517+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2518+ if (!ConstCoeff )
25252519 return false ;
2526- APInt ConstCoeff = Constant-> getAPInt ();
2527- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff. abs ());
2520+ RunningGCD =
2521+ APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff-> abs ());
25282522 }
25292523 Inner = AddRec->getStart ();
25302524 }
@@ -2537,24 +2531,23 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
25372531 else {
25382532 // If the coefficient is the product of a constant and other stuff,
25392533 // we can use the constant in the GCD computation.
2540- Constant = getConstantPart (Coeff);
2541- if (!Constant )
2534+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2535+ if (!ConstCoeff )
25422536 return false ;
2543- APInt ConstCoeff = Constant-> getAPInt ();
2544- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff. abs ());
2537+ RunningGCD =
2538+ APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff-> abs ());
25452539 }
25462540 Inner = AddRec->getStart ();
25472541 }
25482542 Delta = SE->getMinusSCEV (SrcCoeff, DstCoeff);
25492543 // If the coefficient is the product of a constant and other stuff,
25502544 // we can use the constant in the GCD computation.
2551- Constant = getConstantPart (Delta);
2552- if (!Constant )
2545+ std::optional<APInt> ConstCoeff = getConstantPart (Delta);
2546+ if (!ConstCoeff )
25532547 // The difference of the two coefficients might not be a product
25542548 // or constant, in which case we give up on this direction.
25552549 continue ;
2556- APInt ConstCoeff = Constant->getAPInt ();
2557- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2550+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
25582551 LLVM_DEBUG (dbgs () << " \t RunningGCD = " << RunningGCD << " \n " );
25592552 if (RunningGCD != 0 ) {
25602553 Remainder = ConstDelta.srem (RunningGCD);
0 commit comments