[llvm-branch-commits] [llvm] [AMDGPU][Attributor] Skip update if an AA is at its initial state (PR #114726)
Shilei Tian via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 11 10:09:34 PST 2024
================
@@ -1145,31 +1169,71 @@ struct AAAMDWavesPerEU : public AAAMDSizeRangeAttribute {
auto &InfoCache = static_cast<AMDGPUInformationCache &>(A.getInfoCache());
ChangeStatus Change = ChangeStatus::UNCHANGED;
+ Function *F = getAssociatedFunction();
+
+ const auto *AAFlatWorkGroupSize = A.getAAFor<AAAMDFlatWorkGroupSize>(
+ *this, IRPosition::function(*F), DepClassTy::REQUIRED);
+ if (!AAFlatWorkGroupSize || !AAFlatWorkGroupSize->isValidState()) {
+ LLVM_DEBUG(
+ dbgs() << '[' << getName()
+ << "] AAAMDFlatWorkGroupSize is unavailable or invalid.\n");
+ return ChangeStatus::UNCHANGED;
+ }
+
+ if (AAFlatWorkGroupSize->isAtInitialState()) {
+ LLVM_DEBUG(dbgs() << '[' << getName()
+ << "] AAAMDFlatWorkGroupSize is still at initial "
+ "state. Skip the update.\n");
+ return ChangeStatus::UNCHANGED;
+ }
----------------
shiltian wrote:
There are four states to consider: valid, invalid, best, and worst. An AA typically begins in the _best_ state and transitions toward a "worse" state until reaching the _worst_ state. For most AAs, the invalid state is the worst state, but this is not always true, especially for the `IntegerRangeState`, which we use extensively here.
In the case of `IntegerRangeState`, the worst state is considered invalid **only if** `Known` is set to the worst value (`~0U` by default). Once `Known` is modified, there is no longer invalid state, meaning that `manifest` will always run, and half-baked values are likely to be added. This is why I avoided updating `Known` in #113018 and all related PRs in this stack unless the changes were definitive (i.e., all call sites were seen).
The situation becomes more complex because the _best_ state does not actually represent a valid pair of values in terms of the attribute. However, it must still be considered valid so that updates can occur, allowing `Assumed` to be updated accordingly.
Complications arise further because this AA relies on another AA that uses range state. Similarly, the _best_ state of the dependent AA is not a valid pair of values either. If the dependent AA remains in its _best_ (or _initial_, as introduced in this PR) state, we must skip the update, as its values are effectively nonsensical.
https://github.com/llvm/llvm-project/pull/114726
More information about the llvm-branch-commits
mailing list