Debian Codegraph @

llvm/test/Transforms/LoopInterchange/delay-cachecost-calculation.ll

raw
1 ; REQUIRES: asserts
2
3 ; RUN: opt -passes=loop-interchange -debug -disable-output %s 2>&1 | FileCheck %s
4
5 @A = global [16 x [16 x i32]] zeroinitializer
6
7 ; Check that the CacheCost is calculated only when required. In this case, it
8 ; is computed after passing the legality check.
9 ;
10 ; for (i = 0; i < 16; i++)
11 ; for (j = 0; j < 16; j++)
12 ; A[j][i] += 1;
13
14 ; CHECK: Loops 'for.i.header' and 'for.j' are legal to interchange
15 ; CHECK: Compute CacheCost
16 define void @legal_to_interchange() {
17 entry:
18 br label %for.i.header
19
20 for.i.header:
21 %i = phi i32 [ 0, %entry ], [ %i.next, %for.i.latch ]
22 br label %for.j
23
24 for.j:
25 %j = phi i32 [ 0, %for.i.header ], [ %j.next, %for.j ]
26 %idx = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %j, i32 %i
27 %val = load i32, ptr %idx
28 %inc = add i32 %val, 1
29 store i32 %inc, ptr %idx
30 %j.next = add i32 %j, 1
31 %j.exit = icmp eq i32 %j.next, 16
32 br i1 %j.exit, label %for.i.latch, label %for.j
33
34 for.i.latch:
35 %i.next = add i32 %i, 1
36 %i.exit = icmp eq i32 %i.next, 16
37 br i1 %i.exit, label %exit, label %for.i.header
38
39 exit:
40 ret void
41 }
42
43 ; Check that the CacheCost is not calculated when not required. In this case,
44 ; the legality check always fails so that we do not need to compute the
45 ; CacheCost.
46 ;
47 ; for (i = 0; i < 16; i++)
48 ; for (j = 0; j < 16; j++)
49 ; A[j][i] = A[i][j];
50
51 ; CHECK-NOT: Compute CacheCost
52 define void @illegal_to_interchange() {
53 entry:
54 br label %for.i.header
55
56 for.i.header:
57 %i = phi i32 [ 0, %entry ], [ %i.next, %for.i.latch ]
58 br label %for.j
59
60 for.j:
61 %j = phi i32 [ 0, %for.i.header ], [ %j.next, %for.j ]
62 %idx.load = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %i, i32 %j
63 %idx.store = getelementptr inbounds [16 x [16 x i32]], ptr @A, i32 0, i32 %j, i32 %i
64 %val = load i32, ptr %idx.load
65 store i32 %val, ptr %idx.store
66 %j.next = add i32 %j, 1
67 %j.exit = icmp eq i32 %j.next, 16
68 br i1 %j.exit, label %for.i.latch, label %for.j
69
70 for.i.latch:
71 %i.next = add i32 %i, 1
72 %i.exit = icmp eq i32 %i.next, 16
73 br i1 %i.exit, label %exit, label %for.i.header
74
75 exit:
76 ret void
77 }