Skip to content

[DA] add testcase #116631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/DependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
74 changes: 74 additions & 0 deletions llvm/test/Analysis/DependenceAnalysis/PR31848.ll
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to have more descriptive names, so it is easier to read the test and see the loop structure (e.g. loop.1.header for loop headers, %iv for inductions and so on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just used opt -passes=metarenamer -S a.ll to prepare the testcase with more standard names. I guess we could improve the metarenamer to produce more readable BB and var names.

%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
}
1 change: 1 addition & 0 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
SUPPORTED_ANALYSES = {
"Branch Probability Analysis",
"Cost Model Analysis",
"Dependence Analysis",
"Loop Access Analysis",
"Scalar Evolution Analysis",
}
Expand Down
Loading