diff --git a/include/llvm/Transforms/IPO/Attributor.h b/include/llvm/Transforms/IPO/Attributor.h index 234a384b36b..01b40ff7cc2 100644 --- a/include/llvm/Transforms/IPO/Attributor.h +++ b/include/llvm/Transforms/IPO/Attributor.h @@ -1499,11 +1499,16 @@ struct Attributor { ToBeDeletedFunctions.insert(&F); } - /// If \p V is assumed to be a constant, return it, if it is unclear yet, + /// If \p IRP is assumed to be a constant, return it, if it is unclear yet, /// return None, otherwise return `nullptr`. - Optional getAssumedConstant(const Value &V, + Optional getAssumedConstant(const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation); + Optional getAssumedConstant(const Value &V, + const AbstractAttribute &AA, + bool &UsedAssumedInformation) { + return getAssumedConstant(IRPosition::value(V), AA, UsedAssumedInformation); + } /// If \p V is assumed simplified, return it, if it is unclear yet, /// return None, otherwise return `nullptr`. diff --git a/lib/Transforms/IPO/Attributor.cpp b/lib/Transforms/IPO/Attributor.cpp index 87c772167dc..61659b295f2 100644 --- a/lib/Transforms/IPO/Attributor.cpp +++ b/lib/Transforms/IPO/Attributor.cpp @@ -648,19 +648,19 @@ void IRPosition::verify() { } Optional -Attributor::getAssumedConstant(const Value &V, const AbstractAttribute &AA, +Attributor::getAssumedConstant(const IRPosition &IRP, + const AbstractAttribute &AA, bool &UsedAssumedInformation) { // First check all callbacks provided by outside AAs. If any of them returns // a non-null value that is different from the associated value, or None, we // assume it's simpliied. - IRPosition IRP = IRPosition::value(V, AA.getCallBaseContext()); for (auto &CB : SimplificationCallbacks[IRP]) { Optional SimplifiedV = CB(IRP, &AA, UsedAssumedInformation); if (!SimplifiedV.hasValue()) return llvm::None; - if (*SimplifiedV && *SimplifiedV != &IRP.getAssociatedValue() && - isa(*SimplifiedV)) + if (isa_and_nonnull(*SimplifiedV)) return cast(*SimplifiedV); + return nullptr; } const auto &ValueSimplifyAA = getAAFor(AA, IRP, DepClassTy::NONE); @@ -674,13 +674,12 @@ Attributor::getAssumedConstant(const Value &V, const AbstractAttribute &AA, } if (isa_and_nonnull(SimplifiedV.getValue())) { recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL); - return UndefValue::get(V.getType()); + return UndefValue::get(IRP.getAssociatedType()); } Constant *CI = dyn_cast_or_null(SimplifiedV.getValue()); - if (CI && CI->getType() != V.getType()) { - // TODO: Check for a save conversion. - return nullptr; - } + if (CI) + CI = dyn_cast_or_null( + AA::getWithType(*CI, *IRP.getAssociatedType())); if (CI) recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL); return CI; @@ -695,9 +694,7 @@ Attributor::getAssumedSimplified(const IRPosition &IRP, // assume it's simpliied. for (auto &CB : SimplificationCallbacks[IRP]) { Optional SimplifiedV = CB(IRP, AA, UsedAssumedInformation); - if (!SimplifiedV.hasValue() || - (*SimplifiedV && *SimplifiedV != &IRP.getAssociatedValue())) - return SimplifiedV; + return SimplifiedV; } // If no high-level/outside simplification occured, use AAValueSimplify.