Skip to content

Commit

Permalink
[Attributor][FIX] AAValueConstantRange should not loop unconstrained
Browse files Browse the repository at this point in the history
The old method to avoid unconstrained expansion of the constant range in
a loop did not work as soon as there were multiple instructions in
between the phi and its input. We now take a generic approach and limit
the number of updates as a fallback. The old method is kept as it
catches "the common case" early.
  • Loading branch information
jdoerfert committed Jan 21, 2022
1 parent 7bf9065 commit 37e0c58
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 257 deletions.
19 changes: 18 additions & 1 deletion llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -8497,13 +8497,30 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
/* UseValueSimplify */ false))
return indicatePessimisticFixpoint();

return clampStateAndIndicateChange(getState(), T);
// Ensure that long def-use chains can't cause circular reasoning either by
// introducing a cutoff below.
if (clampStateAndIndicateChange(getState(), T) == ChangeStatus::UNCHANGED)
return ChangeStatus::UNCHANGED;
if (++NumChanges > MaxNumChanges) {
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] performed " << NumChanges
<< " but only " << MaxNumChanges
<< " are allowed to avoid cyclic reasoning.");
return indicatePessimisticFixpoint();
}
return ChangeStatus::CHANGED;
}

/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override {
STATS_DECLTRACK_FLOATING_ATTR(value_range)
}

/// Tracker to bail after too many widening steps of the constant range.
int NumChanges = 0;

/// Upper bound for the number of allowed changes (=widening steps) for the
/// constant range before we give up.
static constexpr int MaxNumChanges = 5;
};

struct AAValueConstantRangeFunction : AAValueConstantRangeImpl {
Expand Down

0 comments on commit 37e0c58

Please sign in to comment.