llvm.org GIT mirror llvm / 17d8569
[SCEV] When printing via -analysis, dump loop disposition There are currently some bugs in tree around SCEV caching an incorrect loop disposition. Printing out loop dispositions will let us write whitebox tests as those are fixed. The dispositions are printed as a list in "inside out" order, i.e. innermost loop first. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268177 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 4 years ago
2 changed file(s) with 98 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
95649564 OS << "\n";
95659565 }
95669566
9567 static StringRef loopDispositionToStr(ScalarEvolution::LoopDisposition LD) {
9568 switch (LD) {
9569 case ScalarEvolution::LoopVariant:
9570 return "Variant";
9571 case ScalarEvolution::LoopInvariant:
9572 return "Invariant";
9573 case ScalarEvolution::LoopComputable:
9574 return "Computable";
9575 }
9576 }
9577
95679578 void ScalarEvolution::print(raw_ostream &OS) const {
95689579 // ScalarEvolution's implementation of the print method is to print
95699580 // out SCEV values of all instructions that are interesting. Doing
96119622 } else {
96129623 OS << *ExitValue;
96139624 }
9625
9626 bool First = true;
9627 for (auto *Iter = L; Iter; Iter = Iter->getParentLoop()) {
9628 if (First) {
9629 OS << "\t\t" "LoopDispositions: [ ";
9630 First = false;
9631 } else {
9632 OS << ", ";
9633 }
9634
9635 OS << loopDispositionToStr(SE.getLoopDisposition(SV, Iter));
9636 }
9637
9638 OS << " ]";
96149639 }
96159640
96169641 OS << "\n";
0 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
1
2 define void @single_loop(i32* %buf, i32 %start) {
3 ; CHECK-LABEL: Classifying expressions for: @single_loop
4 entry:
5 %val = add i32 %start, 400
6 br label %loop
7
8 loop:
9 %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
10 %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
11
12 ; CHECK: %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
13 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable ]
14 ; CHECK: %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
15 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable ]
16 ; CHECK: %val2 = add i32 %start, 400
17 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Invariant ]
18 ; CHECK: %idx.inc = add nsw i32 %idx, 1
19 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable ]
20 ; CHECK: %val3 = load volatile i32, i32* %buf
21 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Variant ]
22
23 %val2 = add i32 %start, 400
24 %idx.inc = add nsw i32 %idx, 1
25 %idx.inc.sext = sext i32 %idx.inc to i64
26 %condition = icmp eq i32 %counter, 1
27 %counter.inc = add i32 %counter, 1
28 %val3 = load volatile i32, i32* %buf
29 br i1 %condition, label %exit, label %loop
30
31 exit:
32 ret void
33 }
34
35
36 define void @nested_loop(double* %p, i64 %m) {
37 ; CHECK-LABEL: Classifying expressions for: @nested_loop
38
39 ; CHECK: %j = phi i64 [ 0, %entry ], [ %j.next, %outer.latch ]
40 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable ]
41 ; CHECK: %i = phi i64 [ 0, %outer.loop ], [ %i.next, %bb ]
42 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable, Variant ]
43 ; CHECK: %j.add = add i64 %j, 100
44 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Invariant, Computable ]
45 ; CHECK: %i.next = add i64 %i, 1
46 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable, Variant ]
47 ; CHECK: %j.next = add i64 %j, 91
48 ; CHECK-NEXT: --> {{.*}} LoopDispositions: [ Computable ]
49
50 entry:
51 %k = icmp sgt i64 %m, 0
52 br i1 %k, label %outer.loop, label %return
53
54 outer.loop:
55 %j = phi i64 [ 0, %entry ], [ %j.next, %outer.latch ]
56 br label %bb
57
58 bb:
59 %i = phi i64 [ 0, %outer.loop ], [ %i.next, %bb ]
60 %j.add = add i64 %j, 100
61 %i.next = add i64 %i, 1
62 %exitcond = icmp eq i64 %i.next, 91
63 br i1 %exitcond, label %outer.latch, label %bb
64
65 outer.latch:
66 %j.next = add i64 %j, 91
67 %h = icmp eq i64 %j.next, %m
68 br i1 %h, label %return, label %outer.loop
69
70 return:
71 ret void
72 }