Skip to content

Commit 3dca839

Browse files
committed
Reapply "[Attributor] Disable simplification AAs if a callback is present""
This reapplies commit cbb709e and includes the use of the lookup method instead of operator[] to avoid accidentally setting (empty) simplification callbacks. This reverts commit aa27430.
1 parent 2ca3937 commit 3dca839

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,11 @@ struct Attributor {
15631563
SimplificationCallbacks[IRP].emplace_back(CB);
15641564
}
15651565

1566+
/// Return true if there is a simplification callback for \p IRP.
1567+
bool hasSimplificationCallback(const IRPosition &IRP) {
1568+
return SimplificationCallbacks.count(IRP);
1569+
}
1570+
15661571
private:
15671572
/// The vector with all simplification callbacks registered by outside AAs.
15681573
DenseMap<IRPosition, SmallVector<SimplifictionCallbackTy, 1>>

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ Attributor::getAssumedConstant(const IRPosition &IRP,
761761
// First check all callbacks provided by outside AAs. If any of them returns
762762
// a non-null value that is different from the associated value, or None, we
763763
// assume it's simpliied.
764-
for (auto &CB : SimplificationCallbacks[IRP]) {
764+
for (auto &CB : SimplificationCallbacks.lookup(IRP)) {
765765
Optional<Value *> SimplifiedV = CB(IRP, &AA, UsedAssumedInformation);
766766
if (!SimplifiedV.hasValue())
767767
return llvm::None;
@@ -799,7 +799,7 @@ Attributor::getAssumedSimplified(const IRPosition &IRP,
799799
// First check all callbacks provided by outside AAs. If any of them returns
800800
// a non-null value that is different from the associated value, or None, we
801801
// assume it's simpliied.
802-
for (auto &CB : SimplificationCallbacks[IRP])
802+
for (auto &CB : SimplificationCallbacks.lookup(IRP))
803803
return CB(IRP, AA, UsedAssumedInformation);
804804

805805
// If no high-level/outside simplification occured, use AAValueSimplify.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,6 +5067,8 @@ struct AAValueSimplifyImpl : AAValueSimplify {
50675067
void initialize(Attributor &A) override {
50685068
if (getAssociatedValue().getType()->isVoidTy())
50695069
indicatePessimisticFixpoint();
5070+
if (A.hasSimplificationCallback(getIRPosition()))
5071+
indicatePessimisticFixpoint();
50705072
}
50715073

50725074
/// See AbstractAttribute::getAsStr().
@@ -5400,9 +5402,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl {
54005402

54015403
/// See AbstractAttribute::initialize(...).
54025404
void initialize(Attributor &A) override {
5403-
// FIXME: This might have exposed a SCC iterator update bug in the old PM.
5404-
// Needs investigation.
5405-
// AAValueSimplifyImpl::initialize(A);
5405+
AAValueSimplifyImpl::initialize(A);
54065406
Value &V = getAnchorValue();
54075407

54085408
// TODO: add other stuffs
@@ -5639,6 +5639,7 @@ struct AAValueSimplifyCallSiteReturned : AAValueSimplifyImpl {
56395639
: AAValueSimplifyImpl(IRP, A) {}
56405640

56415641
void initialize(Attributor &A) override {
5642+
AAValueSimplifyImpl::initialize(A);
56425643
if (!getAssociatedFunction())
56435644
indicatePessimisticFixpoint();
56445645
}
@@ -7888,6 +7889,20 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
78887889
AAValueConstantRangeImpl(const IRPosition &IRP, Attributor &A)
78897890
: AAValueConstantRange(IRP, A) {}
78907891

7892+
/// See AbstractAttribute::initialize(..).
7893+
void initialize(Attributor &A) override {
7894+
if (A.hasSimplificationCallback(getIRPosition())) {
7895+
indicatePessimisticFixpoint();
7896+
return;
7897+
}
7898+
7899+
// Intersect a range given by SCEV.
7900+
intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
7901+
7902+
// Intersect a range given by LVI.
7903+
intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
7904+
}
7905+
78917906
/// See AbstractAttribute::getAsStr().
78927907
const std::string getAsStr() const override {
78937908
std::string Str;
@@ -8019,15 +8034,6 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
80198034
return getAssumed().intersectWith(SCEVR).intersectWith(LVIR);
80208035
}
80218036

8022-
/// See AbstractAttribute::initialize(..).
8023-
void initialize(Attributor &A) override {
8024-
// Intersect a range given by SCEV.
8025-
intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
8026-
8027-
// Intersect a range given by LVI.
8028-
intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
8029-
}
8030-
80318037
/// Helper function to create MDNode for range metadata.
80328038
static MDNode *
80338039
getMDNodeForConstantRange(Type *Ty, LLVMContext &Ctx,
@@ -8157,6 +8163,9 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
81578163
/// See AbstractAttribute::initialize(...).
81588164
void initialize(Attributor &A) override {
81598165
AAValueConstantRangeImpl::initialize(A);
8166+
if (isAtFixpoint())
8167+
return;
8168+
81608169
Value &V = getAssociatedValue();
81618170

81628171
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@@ -8177,6 +8186,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
81778186

81788187
if (isa<BinaryOperator>(&V) || isa<CmpInst>(&V) || isa<CastInst>(&V))
81798188
return;
8189+
81808190
// If it is a load instruction with range metadata, use it.
81818191
if (LoadInst *LI = dyn_cast<LoadInst>(&V))
81828192
if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) {
@@ -8504,6 +8514,14 @@ struct AAPotentialValuesImpl : AAPotentialValues {
85048514
AAPotentialValuesImpl(const IRPosition &IRP, Attributor &A)
85058515
: AAPotentialValues(IRP, A) {}
85068516

8517+
/// See AbstractAttribute::initialize(..).
8518+
void initialize(Attributor &A) override {
8519+
if (A.hasSimplificationCallback(getIRPosition()))
8520+
indicatePessimisticFixpoint();
8521+
else
8522+
AAPotentialValues::initialize(A);
8523+
}
8524+
85078525
/// See AbstractAttribute::getAsStr().
85088526
const std::string getAsStr() const override {
85098527
std::string Str;
@@ -8561,6 +8579,10 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
85618579

85628580
/// See AbstractAttribute::initialize(..).
85638581
void initialize(Attributor &A) override {
8582+
AAPotentialValuesImpl::initialize(A);
8583+
if (isAtFixpoint())
8584+
return;
8585+
85648586
Value &V = getAssociatedValue();
85658587

85668588
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@@ -9093,6 +9115,10 @@ struct AAPotentialValuesCallSiteArgument : AAPotentialValuesFloating {
90939115

90949116
/// See AbstractAttribute::initialize(..).
90959117
void initialize(Attributor &A) override {
9118+
AAPotentialValuesImpl::initialize(A);
9119+
if (isAtFixpoint())
9120+
return;
9121+
90969122
Value &V = getAssociatedValue();
90979123

90989124
if (auto *C = dyn_cast<ConstantInt>(&V)) {

0 commit comments

Comments
 (0)