[llvm] [DA] add testcase (PR #116631)

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 16:52:50 PST 2024


https://github.com/sebpop updated https://github.com/llvm/llvm-project/pull/116631

>From e6b1e5d93f2ae33301fb05df4499051773aa3729 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <spop at nvidia.com>
Date: Mon, 25 Nov 2024 18:05:19 +0000
Subject: [PATCH 1/2] [DA] enable update_analyze_test_checks.py

---
 llvm/lib/Analysis/DependenceAnalysis.cpp | 3 ++-
 llvm/utils/UpdateTestChecks/common.py    | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index a4a98ea0bae146..440af7cdfe3ae2 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -216,7 +216,8 @@ void DependenceAnalysisWrapperPass::print(raw_ostream &OS,
 
 PreservedAnalyses
 DependenceAnalysisPrinterPass::run(Function &F, FunctionAnalysisManager &FAM) {
-  OS << "'Dependence Analysis' for function '" << F.getName() << "':\n";
+  OS << "Printing analysis 'Dependence Analysis' for function '" << F.getName()
+     << "':\n";
   dumpExampleDependence(OS, &FAM.getResult<DependenceAnalysis>(F),
                         FAM.getResult<ScalarEvolutionAnalysis>(F),
                         NormalizeResults);
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index b108a21dbc52b8..ead406a3abd318 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -35,6 +35,7 @@
 SUPPORTED_ANALYSES = {
     "Branch Probability Analysis",
     "Cost Model Analysis",
+    "Dependence Analysis",
     "Loop Access Analysis",
     "Scalar Evolution Analysis",
 }

>From d66d466fdc4db69be779bb84f39d94de2619c14e Mon Sep 17 00:00:00 2001
From: Sebastian Pop <spop at nvidia.com>
Date: Thu, 14 Nov 2024 20:52:54 +0000
Subject: [PATCH 2/2] [DA] add testcase

Make sure the testcase for this bug continues to work:
https://github.com/llvm/llvm-project/issues/31196
---
 .../Analysis/DependenceAnalysis/PR31848.ll    | 74 +++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 llvm/test/Analysis/DependenceAnalysis/PR31848.ll

diff --git a/llvm/test/Analysis/DependenceAnalysis/PR31848.ll b/llvm/test/Analysis/DependenceAnalysis/PR31848.ll
new file mode 100644
index 00000000000000..8ee1224a18ad1f
--- /dev/null
+++ b/llvm/test/Analysis/DependenceAnalysis/PR31848.ll
@@ -0,0 +1,74 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 \
+; RUN: | FileCheck %s
+
+; DependenceAnalysis used to run into a heap buffer overflow on this testcase.
+; See https://github.com/llvm/llvm-project/issues/31196 for details.
+
+define void @barney(ptr nocapture %arg, i32 %arg1) {
+; CHECK-LABEL: 'barney'
+; CHECK-NEXT:  Src: store i32 7, ptr %getelementptr, align 4 --> Dst: store i32 7, ptr %getelementptr, align 4
+; CHECK-NEXT:    da analyze - output [* * * *]!
+;
+bb:
+  %icmp = icmp sgt i32 %arg1, 0
+  br i1 %icmp, label %bb2, label %bb31
+
+bb2:                                              ; preds = %bb28, %bb
+  %phi = phi i32 [ %add29, %bb28 ], [ 0, %bb ]
+  br label %bb3
+
+bb3:                                              ; preds = %bb25, %bb2
+  %phi4 = phi i32 [ %add26, %bb25 ], [ 0, %bb2 ]
+  br label %bb5
+
+bb5:                                              ; preds = %bb22, %bb3
+  %phi6 = phi i32 [ -1, %bb3 ], [ %add23, %bb22 ]
+  %add7 = add nsw i32 %phi6, %phi4
+  br label %bb8
+
+bb8:                                              ; preds = %bb19, %bb5
+  %phi9 = phi i32 [ -1, %bb5 ], [ %add20, %bb19 ]
+  %add10 = add nsw i32 %phi9, %phi
+  br label %bb11
+
+bb11:                                             ; preds = %bb11, %bb8
+  %phi12 = phi i32 [ %add7, %bb8 ], [ %add14, %bb11 ]
+  %icmp13 = icmp slt i32 %phi12, 0
+  %add14 = add nsw i32 %phi12, %arg1
+  br i1 %icmp13, label %bb11, label %bb15
+
+bb15:                                             ; preds = %bb15, %bb11
+  %phi16 = phi i32 [ %add18, %bb15 ], [ %add10, %bb11 ]
+  %icmp17 = icmp slt i32 %phi16, 0
+  %add18 = add nsw i32 %phi16, %arg1
+  br i1 %icmp17, label %bb15, label %bb19
+
+bb19:                                             ; preds = %bb15
+  %mul = mul nsw i32 %phi16, %arg1
+  %add = add nsw i32 %mul, %phi12
+  %sext = sext i32 %add to i64
+  %getelementptr = getelementptr inbounds i32, ptr %arg, i64 %sext
+  store i32 7, ptr %getelementptr, align 4
+  %add20 = add nsw i32 %phi9, 1
+  %icmp21 = icmp eq i32 %add20, 2
+  br i1 %icmp21, label %bb22, label %bb8
+
+bb22:                                             ; preds = %bb19
+  %add23 = add nsw i32 %phi6, 1
+  %icmp24 = icmp eq i32 %add23, 2
+  br i1 %icmp24, label %bb25, label %bb5
+
+bb25:                                             ; preds = %bb22
+  %add26 = add nuw nsw i32 %phi4, 1
+  %icmp27 = icmp eq i32 %add26, %arg1
+  br i1 %icmp27, label %bb28, label %bb3
+
+bb28:                                             ; preds = %bb25
+  %add29 = add nuw nsw i32 %phi, 1
+  %icmp30 = icmp eq i32 %add29, %arg1
+  br i1 %icmp30, label %bb31, label %bb2
+
+bb31:                                             ; preds = %bb28, %bb
+  ret void
+}



More information about the llvm-commits mailing list