Skip to content

Conversation

@aleks-tmb
Copy link
Contributor

No description provided.

@aleks-tmb aleks-tmb self-assigned this Feb 17, 2025
@aleks-tmb aleks-tmb requested a review from nikic as a code owner February 17, 2025 23:10
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Feb 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 17, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Aleksandr Popov (aleks-tmb)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/127550.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+10)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 8f74c1c398ced..2d1a57a72721d 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14482,6 +14482,16 @@ void ScalarEvolution::verify() const {
                << "Delta: " << *Delta << "\n";
         std::abort();
       }
+
+      if (isa<PHINode>(I))
+        for (const Loop *L : ValidLoops)
+          if (SE.isAvailableAtLoopEntry(OldSCEV, L) !=
+              SE2.isAvailableAtLoopEntry(NewSCEV, L)) {
+            dbgs() << "Incorrect SCEV availability at loop entry\n"
+                   << "Old: " << *OldSCEV << "\n"
+                   << "New: " << *NewSCEV << "\n";
+            std::abort();
+          }
     }
   }
 

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the existing loop and block disposition verification catch this? isAvailableAtEntry is a combination of LoopInvariant and ProperlyDominatesBlock dispositions.

@nikic nikic requested a review from fhahn February 18, 2025 16:52
@aleks-tmb
Copy link
Contributor Author

Why doesn't the existing loop and block disposition verification catch this? isAvailableAtEntry is a combination of LoopInvariant and ProperlyDominatesBlock dispositions.

The motivating example can be found here: #127534.
In this case, both LoopDispositions and BlockDispositions are empty

@aleks-tmb
Copy link
Contributor Author

@nikic @fhahn Hi,

Here’s another case of missing SCEV invalidation, which leads to incorrect availability at the loop entry: #130930

The reason the existing loop and block disposition verification doesn't catch this issue is that disposition caches are cleared inside the loop-simplifycfg pass.
However, when isAvailableAtLoopEntry is called, it recomputes the disposition for the cached SCEV and exposes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants