From bde4574fcb3fafddf6211b96859393918ce61d7b Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 7 May 2014 19:00:32 +0000 Subject: [PATCH] do not collect undef terms git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208237 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 37 +++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 7d84dbee5c5..c44c13b04fc 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -6815,6 +6815,40 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, return SE.getCouldNotCompute(); } +namespace { +struct FindUndefs { + bool Found; + FindUndefs() : Found(false) {} + + bool follow(const SCEV *S) { + if (const SCEVUnknown *C = dyn_cast(S)) { + if (isa(C->getValue())) + Found = true; + } else if (const SCEVConstant *C = dyn_cast(S)) { + if (isa(C->getValue())) + Found = true; + } + + // Keep looking if we haven't found it yet. + return !Found; + } + bool isDone() const { + // Stop recursion if we have found an undef. + return Found; + } +}; +} + +// Return true when S contains at least an undef value. +static inline bool +containsUndefs(const SCEV *S) { + FindUndefs F; + SCEVTraversal ST(F); + ST.visitAll(S); + + return F.Found; +} + namespace { // Collect all steps of SCEV expressions. struct SCEVCollectStrides { @@ -6841,7 +6875,8 @@ struct SCEVCollectTerms { bool follow(const SCEV *S) { if (isa(S) || isa(S) || isa(S)) { - Terms.push_back(S); + if (!containsUndefs(S)) + Terms.push_back(S); // Stop recursion: once we collected a term, do not walk its operands. return false;