[llvm] improve debug messages in dependence analysis (PR #156367)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 11:32:30 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Sebastian Pop (sebpop)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+34-12) 


``````````diff
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index f33e04e804e3d..da86a8d2cc9c0 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -3419,13 +3419,24 @@ bool DependenceInfo::tryDelinearizeFixedSize(
       size_t SSize = Subscripts.size();
       for (size_t I = 1; I < SSize; ++I) {
         const SCEV *S = Subscripts[I];
-        if (!isKnownNonNegative(S, Ptr))
+        if (!isKnownNonNegative(S, Ptr)) {
+          LLVM_DEBUG({
+            dbgs() << "Check failed: !isKnownNonNegative(S, Ptr)\n";
+            dbgs() << "  S: " << *S << "\n" << "  Ptr: " << *Ptr << "\n";
+          });
           return false;
+        }
         if (auto *SType = dyn_cast<IntegerType>(S->getType())) {
           const SCEV *Range = SE->getConstant(
               ConstantInt::get(SType, DimensionSizes[I - 1], false));
-          if (!isKnownLessThan(S, Range))
+          if (!isKnownLessThan(S, Range)) {
+            LLVM_DEBUG({
+              dbgs() << "Check failed: !isKnownLessThan(S, Range)\n";
+              dbgs() << "  S: " << *S << "\n"
+                     << "  Range: " << *Range << "\n";
+            });
             return false;
+          }
         }
       }
       return true;
@@ -3433,6 +3444,7 @@ bool DependenceInfo::tryDelinearizeFixedSize(
 
     if (!AllIndicesInRange(SrcSizes, SrcSubscripts, SrcPtr) ||
         !AllIndicesInRange(DstSizes, DstSubscripts, DstPtr)) {
+      LLVM_DEBUG(dbgs() << "Check failed: AllIndicesInRange.\n");
       SrcSubscripts.clear();
       DstSubscripts.clear();
       return false;
@@ -3500,17 +3512,27 @@ bool DependenceInfo::tryDelinearizeParametricSize(
   // to the dependency checks.
   if (!DisableDelinearizationChecks)
     for (size_t I = 1; I < Size; ++I) {
-      if (!isKnownNonNegative(SrcSubscripts[I], SrcPtr))
-        return false;
-
-      if (!isKnownLessThan(SrcSubscripts[I], Sizes[I - 1]))
-        return false;
-
-      if (!isKnownNonNegative(DstSubscripts[I], DstPtr))
-        return false;
+      bool SNN = isKnownNonNegative(SrcSubscripts[I], SrcPtr);
+      bool DNN = isKnownNonNegative(DstSubscripts[I], DstPtr);
+      bool SLT = isKnownLessThan(SrcSubscripts[I], Sizes[I - 1]);
+      bool DLT = isKnownLessThan(DstSubscripts[I], Sizes[I - 1]);
+      if (SNN && DNN && SLT && DLT)
+        continue;
 
-      if (!isKnownLessThan(DstSubscripts[I], Sizes[I - 1]))
-        return false;
+      LLVM_DEBUG({
+        dbgs() << "Delinearization checks failed: can't prove the following\n";
+        if (!SNN)
+          dbgs() << "  isKnownNonNegative(" << *SrcSubscripts[I] << ")\n";
+        if (!DNN)
+          dbgs() << "  isKnownNonNegative(" << *DstSubscripts[I] << ")\n";
+        if (!SLT)
+          dbgs() << "  isKnownLessThan(" << *SrcSubscripts[I] << ", "
+                 << *Sizes[I - 1] << ")\n";
+        if (!DLT)
+          dbgs() << "  isKnownLessThan(" << *DstSubscripts[I] << ", "
+                 << *Sizes[I - 1] << ")\n";
+      });
+      return false;
     }
 
   return true;

``````````

</details>


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


More information about the llvm-commits mailing list