[llvm] 3dca839 - Reapply "[Attributor] Disable simplification AAs if a callback is present""
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 27 17:15:13 PDT 2021
Author: Johannes Doerfert
Date: 2021-07-27T19:14:50-05:00
New Revision: 3dca83961c9a35b6f640d9f7fdc244ec07bffe71
URL: https://github.com/llvm/llvm-project/commit/3dca83961c9a35b6f640d9f7fdc244ec07bffe71
DIFF: https://github.com/llvm/llvm-project/commit/3dca83961c9a35b6f640d9f7fdc244ec07bffe71.diff
LOG: Reapply "[Attributor] Disable simplification AAs if a callback is present""
This reapplies commit cbb709e25124dc38ee593882051fc88c987fe591 and
includes the use of the lookup method instead of operator[] to avoid
accidentally setting (empty) simplification callbacks.
This reverts commit aa27430a625b2fd059707a87f8ba2df8f480ff11.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 25f3f2ccfb1bf..c93b8adcc8901 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1563,6 +1563,11 @@ struct Attributor {
SimplificationCallbacks[IRP].emplace_back(CB);
}
+ /// Return true if there is a simplification callback for \p IRP.
+ bool hasSimplificationCallback(const IRPosition &IRP) {
+ return SimplificationCallbacks.count(IRP);
+ }
+
private:
/// The vector with all simplification callbacks registered by outside AAs.
DenseMap<IRPosition, SmallVector<SimplifictionCallbackTy, 1>>
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index d947df259f39f..762317425026b 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -761,7 +761,7 @@ Attributor::getAssumedConstant(const IRPosition &IRP,
// First check all callbacks provided by outside AAs. If any of them returns
// a non-null value that is
diff erent from the associated value, or None, we
// assume it's simpliied.
- for (auto &CB : SimplificationCallbacks[IRP]) {
+ for (auto &CB : SimplificationCallbacks.lookup(IRP)) {
Optional<Value *> SimplifiedV = CB(IRP, &AA, UsedAssumedInformation);
if (!SimplifiedV.hasValue())
return llvm::None;
@@ -799,7 +799,7 @@ Attributor::getAssumedSimplified(const IRPosition &IRP,
// First check all callbacks provided by outside AAs. If any of them returns
// a non-null value that is
diff erent from the associated value, or None, we
// assume it's simpliied.
- for (auto &CB : SimplificationCallbacks[IRP])
+ for (auto &CB : SimplificationCallbacks.lookup(IRP))
return CB(IRP, AA, UsedAssumedInformation);
// If no high-level/outside simplification occured, use AAValueSimplify.
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 8c5416bd4b6a3..98ce286d5139a 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5067,6 +5067,8 @@ struct AAValueSimplifyImpl : AAValueSimplify {
void initialize(Attributor &A) override {
if (getAssociatedValue().getType()->isVoidTy())
indicatePessimisticFixpoint();
+ if (A.hasSimplificationCallback(getIRPosition()))
+ indicatePessimisticFixpoint();
}
/// See AbstractAttribute::getAsStr().
@@ -5400,9 +5402,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl {
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
- // FIXME: This might have exposed a SCC iterator update bug in the old PM.
- // Needs investigation.
- // AAValueSimplifyImpl::initialize(A);
+ AAValueSimplifyImpl::initialize(A);
Value &V = getAnchorValue();
// TODO: add other stuffs
@@ -5639,6 +5639,7 @@ struct AAValueSimplifyCallSiteReturned : AAValueSimplifyImpl {
: AAValueSimplifyImpl(IRP, A) {}
void initialize(Attributor &A) override {
+ AAValueSimplifyImpl::initialize(A);
if (!getAssociatedFunction())
indicatePessimisticFixpoint();
}
@@ -7888,6 +7889,20 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
AAValueConstantRangeImpl(const IRPosition &IRP, Attributor &A)
: AAValueConstantRange(IRP, A) {}
+ /// See AbstractAttribute::initialize(..).
+ void initialize(Attributor &A) override {
+ if (A.hasSimplificationCallback(getIRPosition())) {
+ indicatePessimisticFixpoint();
+ return;
+ }
+
+ // Intersect a range given by SCEV.
+ intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
+
+ // Intersect a range given by LVI.
+ intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
+ }
+
/// See AbstractAttribute::getAsStr().
const std::string getAsStr() const override {
std::string Str;
@@ -8019,15 +8034,6 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
return getAssumed().intersectWith(SCEVR).intersectWith(LVIR);
}
- /// See AbstractAttribute::initialize(..).
- void initialize(Attributor &A) override {
- // Intersect a range given by SCEV.
- intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
-
- // Intersect a range given by LVI.
- intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
- }
-
/// Helper function to create MDNode for range metadata.
static MDNode *
getMDNodeForConstantRange(Type *Ty, LLVMContext &Ctx,
@@ -8157,6 +8163,9 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
AAValueConstantRangeImpl::initialize(A);
+ if (isAtFixpoint())
+ return;
+
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@@ -8177,6 +8186,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
if (isa<BinaryOperator>(&V) || isa<CmpInst>(&V) || isa<CastInst>(&V))
return;
+
// If it is a load instruction with range metadata, use it.
if (LoadInst *LI = dyn_cast<LoadInst>(&V))
if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) {
@@ -8504,6 +8514,14 @@ struct AAPotentialValuesImpl : AAPotentialValues {
AAPotentialValuesImpl(const IRPosition &IRP, Attributor &A)
: AAPotentialValues(IRP, A) {}
+ /// See AbstractAttribute::initialize(..).
+ void initialize(Attributor &A) override {
+ if (A.hasSimplificationCallback(getIRPosition()))
+ indicatePessimisticFixpoint();
+ else
+ AAPotentialValues::initialize(A);
+ }
+
/// See AbstractAttribute::getAsStr().
const std::string getAsStr() const override {
std::string Str;
@@ -8561,6 +8579,10 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
+ AAPotentialValuesImpl::initialize(A);
+ if (isAtFixpoint())
+ return;
+
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@@ -9093,6 +9115,10 @@ struct AAPotentialValuesCallSiteArgument : AAPotentialValuesFloating {
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
+ AAPotentialValuesImpl::initialize(A);
+ if (isAtFixpoint())
+ return;
+
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {
More information about the llvm-commits
mailing list