Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp =================================================================== --- llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -4474,24 +4474,42 @@ return true; } - bool askSimplifiedValueForAAValueConstantRange(Attributor &A) { + /// Returns a candidate is found or not + /// \p failAll is true when nullptr is returned by all other AAs + /// If at least one AA returns llvm::None, a candidate may be found in later + /// iteration. + template + bool askSimplifiedValueFor(Attributor &A, bool &failAll) { if (!getAssociatedValue().getType()->isIntegerTy()) return false; - const auto &ValueConstantRangeAA = - A.getAAFor(*this, getIRPosition()); + const auto &AA = + A.getAAFor(*this, getIRPosition(), /* TrackDependence */ true, + DepClassTy::OPTIONAL); - Optional COpt = - ValueConstantRangeAA.getAssumedConstantInt(A); - if (COpt.hasValue()) { - if (auto *C = COpt.getValue()) + Optional COpt = AA.getAssumedConstantInt(A); + + if (!COpt.hasValue()) { + failAll = false; + return false; + } else { + if (auto *C = COpt.getValue()) { SimplifiedAssociatedValue = C; - else + return true; + } else { return false; - } else { - SimplifiedAssociatedValue = llvm::None; + } } - return true; + } + + bool askSimplifiedValueForOtherAAs(Attributor &A) { + bool failAll = true; + SimplifiedAssociatedValue = llvm::None; + if (askSimplifiedValueFor(A, failAll)) + return true; + if (askSimplifiedValueFor(A, failAll)) + return true; + return !failAll; } /// See AbstractAttribute::manifest(...). @@ -4598,7 +4616,7 @@ bool AllCallSitesKnown; if (!A.checkForAllCallSites(PredForCallSite, *this, true, AllCallSitesKnown)) - if (!askSimplifiedValueForAAValueConstantRange(A)) + if (!askSimplifiedValueForOtherAAs(A)) return indicatePessimisticFixpoint(); // If a candicate was found in this update, return CHANGED. @@ -4626,7 +4644,7 @@ }; if (!A.checkForAllReturnedValues(PredForReturned, *this)) - if (!askSimplifiedValueForAAValueConstantRange(A)) + if (!askSimplifiedValueForOtherAAs(A)) return indicatePessimisticFixpoint(); // If a candicate was found in this update, return CHANGED. @@ -4716,7 +4734,7 @@ if (!genericValueTraversal( A, getIRPosition(), *this, Dummy, VisitValueCB, getCtxI(), /* UseValueSimplify */ false)) - if (!askSimplifiedValueForAAValueConstantRange(A)) + if (!askSimplifiedValueForOtherAAs(A)) return indicatePessimisticFixpoint(); // If a candicate was found in this update, return CHANGED.