[llvm-branch-commits] [llvm] [DA] Extract negating dependence logic (NFCI) (PR #185576)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 9 23:56:55 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Ryotaro Kasuga (kasuga-fj)

<details>
<summary>Changes</summary>

Extract the logic to negate the dependence object from `Dependence::normalize`. The extracted method will be used in the next PR #<!-- -->185577 to refactor the Weak Zero SIV tests.

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


2 Files Affected:

- (modified) llvm/include/llvm/Analysis/DependenceAnalysis.h (+6) 
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+10-7) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/DependenceAnalysis.h b/llvm/include/llvm/Analysis/DependenceAnalysis.h
index b644af3f2ca4a..7ced97c34715b 100644
--- a/llvm/include/llvm/Analysis/DependenceAnalysis.h
+++ b/llvm/include/llvm/Analysis/DependenceAnalysis.h
@@ -169,6 +169,10 @@ class LLVM_ABI Dependence {
   /// vector means Src and Dst are reversed in the actual program.
   virtual bool isDirectionNegative() const { return false; }
 
+  /// Negate the dependence by swapping the source and destination, and
+  /// reversing the direction and distance information.
+  virtual void negate(ScalarEvolution &SE) {}
+
   /// If the direction vector is negative, normalize the direction
   /// vector to make it non-negative. Normalization is done by reversing
   /// Src and Dst, plus reversing the dependence directions and distances
@@ -275,6 +279,8 @@ class LLVM_ABI FullDependence final : public Dependence {
   /// vector means Src and Dst are reversed in the actual program.
   bool isDirectionNegative() const override;
 
+  void negate(ScalarEvolution &SE) override;
+
   /// If the direction vector is negative, normalize the direction
   /// vector to make it non-negative. Normalization is done by reversing
   /// Src and Dst, plus reversing the dependence directions and distances
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 835c79d0e0f3b..29e04e59c414a 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -623,12 +623,7 @@ bool FullDependence::isDirectionNegative() const {
   return false;
 }
 
-bool FullDependence::normalize(ScalarEvolution *SE) {
-  if (!isDirectionNegative())
-    return false;
-
-  LLVM_DEBUG(dbgs() << "Before normalizing negative direction vectors:\n";
-             dump(dbgs()););
+void FullDependence::negate(ScalarEvolution &SE) {
   std::swap(Src, Dst);
   for (unsigned Level = 1; Level <= Levels; ++Level) {
     unsigned char Direction = DV[Level - 1].Direction;
@@ -642,9 +637,17 @@ bool FullDependence::normalize(ScalarEvolution *SE) {
     DV[Level - 1].Direction = RevDirection;
     // Reverse the dependence distance as well.
     if (DV[Level - 1].Distance != nullptr)
-      DV[Level - 1].Distance = SE->getNegativeSCEV(DV[Level - 1].Distance);
+      DV[Level - 1].Distance = SE.getNegativeSCEV(DV[Level - 1].Distance);
   }
+}
 
+bool FullDependence::normalize(ScalarEvolution *SE) {
+  if (!isDirectionNegative())
+    return false;
+
+  LLVM_DEBUG(dbgs() << "Before normalizing negative direction vectors:\n";
+             dump(dbgs()););
+  negate(*SE);
   LLVM_DEBUG(dbgs() << "After normalizing negative direction vectors:\n";
              dump(dbgs()););
   return true;

``````````

</details>


https://github.com/llvm/llvm-project/pull/185576


More information about the llvm-branch-commits mailing list