@@ -1587,6 +1587,15 @@ static const SCEV *minusSCEVNoSignedOverflow(const SCEV *A, const SCEV *B,
15871587 return nullptr ;
15881588}
15891589
1590+ // / Returns \p A * \p B if it guaranteed not to signed wrap. Otherwise returns
1591+ // / nullptr. \p A and \p B must have the same integer type.
1592+ static const SCEV *mulSCEVNoSignedOverflow (const SCEV *A, const SCEV *B,
1593+ ScalarEvolution &SE) {
1594+ if (SE.willNotOverflow (Instruction::Mul, /* Signed=*/ true , A, B))
1595+ return SE.getMulExpr (A, B);
1596+ return nullptr ;
1597+ }
1598+
15901599// / Returns the absolute value of \p A. In the context of dependence analysis,
15911600// / we need an absolute value in a mathematical sense. If \p A is the signed
15921601// / minimum value, we cannot represent it unless extending the original type.
@@ -1686,7 +1695,11 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
16861695 assert (0 < Level && Level <= CommonLevels && " level out of range" );
16871696 Level--;
16881697
1689- const SCEV *Delta = SE->getMinusSCEV (SrcConst, DstConst);
1698+ const SCEV *Delta = minusSCEVNoSignedOverflow (SrcConst, DstConst, *SE);
1699+ if (!Delta) {
1700+ Result.Consistent = false ;
1701+ return false ;
1702+ }
16901703 LLVM_DEBUG (dbgs () << " \t Delta = " << *Delta);
16911704 LLVM_DEBUG (dbgs () << " , " << *Delta->getType () << " \n " );
16921705
@@ -1702,7 +1715,9 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
17021715 const SCEV *AbsCoeff = absSCEVNoSignedOverflow (Coeff, *SE);
17031716 if (!AbsDelta || !AbsCoeff)
17041717 return false ;
1705- const SCEV *Product = SE->getMulExpr (UpperBound, AbsCoeff);
1718+ const SCEV *Product = mulSCEVNoSignedOverflow (UpperBound, AbsCoeff, *SE);
1719+ if (!Product)
1720+ return false ;
17061721 return isKnownPredicate (CmpInst::ICMP_SGT, AbsDelta, Product);
17071722 }();
17081723 if (IsDeltaLarge) {
0 commit comments