xref: /llvm-project/llvm/test/Analysis/DDG/print-dot-ddg.ll (revision 7cf5581712b24d4aea5dffa2e23f0ed42af1954d)
1; RUN: opt -aa-pipeline=basic-aa -passes=dot-ddg -dot-ddg-filename-prefix=%t < %s 2>&1 > /dev/null
2; RUN: FileCheck %s -input-file=%t.foo.for.body.dot
3; RUN: opt -aa-pipeline=basic-aa -passes=dot-ddg -dot-ddg-filename-prefix=%t -dot-ddg-only < %s 2>&1 > /dev/null
4; RUN: FileCheck %s -input-file=%t.foo.for.body.dot -check-prefix=CHECK-ONLY
5
6target datalayout = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
7
8; Test the dot graph printer for a non-trivial DDG graph generated from
9; the following test case. In particular it tests that pi-blocks are
10; printed properly and that multiple memory dependencies on a single edge
11; are shown in the full dot graph.
12;
13; void foo(ptr restrict A, ptr restrict B, int n) {
14;   for (int i = 0; i < n; i++) {
15;     A[i] = A[i] + B[i];
16;     B[i+1] = A[i] + 1;
17;   }
18; }
19
20
21; CHECK: digraph "DDG for 'foo.for.body'"
22; CHECK-NEXT: label="DDG for 'foo.for.body'";
23; CHECK: {{Node0x.*}} [shape=record,label="{\<kind:root\>\nroot\n}"]
24; CHECK: {{Node0x.*}} -> {{Node0x.*}}[label="[rooted]"]
25; CHECK-COUNT-6: {{Node0x.*}} -> {{Node0x.*}}[label="[def-use]"]
26; CHECK-NOT: {{Node0x.*}} -> {{Node0x.*}}[label="[def-use]"]
27; CHECK: [shape=record,label="{\<kind:single-instruction\>\n  %arrayidx10 = getelementptr inbounds float, ptr %B, i64 %indvars.iv.next\n}"];
28; CHECK: [shape=record,label="{\<kind:multi-instruction\>\n  %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n  %0 = load float, ptr %arrayidx, align 4\n}"];
29; CHECK: {{Node0x.*}} -> {{Node0x.*}}[label="[consistent anti [0|<]!, consistent input [0|<]!]"]
30; CHECK: [shape=record,label="{\<kind:pi-block\>\n--- start of nodes in pi-block ---\n\<kind:single-instruction\>\n  %1 = load float, ptr %arrayidx2, align 4\n\n\<kind:single-instruction\>\n  %add = fadd fast float %0, %1\n\n\<kind:single-instruction\>\n  store float %add, ptr %arrayidx4, align 4\n\n\<kind:multi-instruction\>\n  %2 = load float, ptr %arrayidx6, align 4\n  %add7 = fadd fast float %2, 1.000000e+00\n\n\<kind:single-instruction\>\n  store float %add7, ptr %arrayidx10, align 4\n--- end of nodes in pi-block ---\n}"];
31
32; CHECK-ONLY: digraph "DDG for 'foo.for.body'"
33; CHECK-ONLY-NEXT: label="DDG for 'foo.for.body'";
34; CHECK-ONLY: [shape=record,label="{pi-block\nwith\n2 nodes\n}"];
35; CHECK-ONLY-COUNT-6: {{Node0x.*}} -> {{Node0x.*}}[label="[def-use]"];
36; CHECK-NOT: {{Node0x.*}} -> {{Node0x.*}}[label="[def-use]"];
37; CHECK-ONLY: [shape=record,label="{  %arrayidx10 = getelementptr inbounds float, ptr %B, i64 %indvars.iv.next\n}"];
38; CHECK-ONLY: [shape=record,label="{  %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n  %0 = load float, ptr %arrayidx, align 4\n}"];
39; CHECK-ONLY: {{Node0x.*}} -> {{Node0x.*}}[label="[memory]"]
40; CHECK-ONLY: [shape=record,label="{pi-block\nwith\n5 nodes\n}"];
41
42define void @foo(ptr noalias %A, ptr noalias %B, i32 signext %n) {
43entry:
44  %cmp1 = icmp sgt i32 %n, 0
45  br i1 %cmp1, label %for.body.preheader, label %for.end
46
47for.body.preheader:                               ; preds = %entry
48  %wide.trip.count = zext i32 %n to i64
49  br label %for.body
50
51for.body:                                         ; preds = %for.body.preheader, %for.body
52  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
53  %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv
54  %0 = load float, ptr %arrayidx, align 4
55  %arrayidx2 = getelementptr inbounds float, ptr %B, i64 %indvars.iv
56  %1 = load float, ptr %arrayidx2, align 4
57  %add = fadd fast float %0, %1
58  %arrayidx4 = getelementptr inbounds float, ptr %A, i64 %indvars.iv
59  store float %add, ptr %arrayidx4, align 4
60  %arrayidx6 = getelementptr inbounds float, ptr %A, i64 %indvars.iv
61  %2 = load float, ptr %arrayidx6, align 4
62  %add7 = fadd fast float %2, 1.000000e+00
63  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
64  %arrayidx10 = getelementptr inbounds float, ptr %B, i64 %indvars.iv.next
65  store float %add7, ptr %arrayidx10, align 4
66  %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
67  br i1 %exitcond, label %for.body, label %for.end.loopexit
68
69for.end.loopexit:                                 ; preds = %for.body
70  br label %for.end
71
72for.end:                                          ; preds = %for.end.loopexit, %entry
73  ret void
74}
75