diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index 853bd66c8a7f8..af900e2a92998 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -1668,17 +1668,35 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst, LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta); LLVM_DEBUG(dbgs() << ", " << *Delta->getType() << "\n"); + TypeSize CoeffSize = + Coeff->getType()->getScalarType()->getPrimitiveSizeInBits(); + TypeSize SrcSize = + SrcConst->getType()->getScalarType()->getPrimitiveSizeInBits(); + TypeSize DstSize = + DstConst->getType()->getScalarType()->getPrimitiveSizeInBits(); + TypeSize WideSize = std::max(CoeffSize, std::max(SrcSize, DstSize)) * 2; + LLVMContext &Context = CurDstLoop->getHeader()->getParent()->getContext(); + Type *WideTy = IntegerType::get(Context, WideSize); + const SCEV *WideSrcC = SE->getSignExtendExpr(SrcConst, WideTy); + const SCEV *WideDstC = SE->getSignExtendExpr(DstConst, WideTy); + const SCEV *WideDelta = SE->getMinusSCEV(WideSrcC, WideDstC); + const SCEV *WideCoeff = SE->getSignExtendExpr(Coeff, WideTy); + // check that |Delta| < iteration count - if (const SCEV *UpperBound = - collectUpperBound(CurSrcLoop, Delta->getType())) { - LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound); - LLVM_DEBUG(dbgs() << ", " << *UpperBound->getType() << "\n"); - const SCEV *AbsDelta = - SE->isKnownNonNegative(Delta) ? Delta : SE->getNegativeSCEV(Delta); - const SCEV *AbsCoeff = - SE->isKnownNonNegative(Coeff) ? Coeff : SE->getNegativeSCEV(Coeff); - const SCEV *Product = SE->getMulExpr(UpperBound, AbsCoeff); - if (isKnownPredicate(CmpInst::ICMP_SGT, AbsDelta, Product)) { + if (const SCEV *WideUpperBound = + collectUpperBound(CurSrcLoop, WideDelta->getType())) { + LLVM_DEBUG(dbgs() << "\t WideUpperBound = " << *WideUpperBound); + LLVM_DEBUG(dbgs() << ", " << *WideUpperBound->getType() << "\n"); + + // FIXME: Use SCEV getAbsExpr function to compute the abstract values + const SCEV *WideAbsDelta = SE->isKnownNonNegative(WideDelta) + ? WideDelta + : SE->getNegativeSCEV(WideDelta); + const SCEV *WideAbsCoeff = SE->isKnownNonNegative(WideCoeff) + ? WideCoeff + : SE->getNegativeSCEV(WideCoeff); + const SCEV *WideProduct = SE->getMulExpr(WideUpperBound, WideAbsCoeff); + if (isKnownPredicate(CmpInst::ICMP_SGT, WideAbsDelta, WideProduct)) { // Distance greater than trip count - no dependence ++StrongSIVindependence; ++StrongSIVsuccesses;