1; RUN: opt < %s -S -falkor-hwpf-fix -mtriple aarch64 -mcpu=falkor | FileCheck %s
2; RUN: opt < %s -S -falkor-hwpf-fix -mtriple aarch64 -mcpu=cortex-a57 | FileCheck %s --check-prefix=NOHWPF
3
4; Check that strided access metadata is added to loads in inner loops when compiling for Falkor.
5
6; CHECK-LABEL: @hwpf1(
7; CHECK: load i32, i32* %gep, !falkor.strided.access !0
8; CHECK: load i32, i32* %gep2, !falkor.strided.access !0
9
10; NOHWPF-LABEL: @hwpf1(
11; NOHWPF: load i32, i32* %gep{{$}}
12; NOHWPF: load i32, i32* %gep2{{$}}
13define void @hwpf1(i32* %p, i32* %p2) {
14entry:
15  br label %loop
16
17loop:
18  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
19
20  %gep = getelementptr inbounds i32, i32* %p, i32 %iv
21  %load = load i32, i32* %gep
22
23  %gep2 = getelementptr inbounds i32, i32* %p2, i32 %iv
24  %load2 = load i32, i32* %gep2
25
26  %inc = add i32 %iv, 1
27  %exitcnd = icmp uge i32 %inc, 1024
28  br i1 %exitcnd, label %exit, label %loop
29
30exit:
31  ret void
32}
33
34; Check that outer loop strided load isn't marked.
35; CHECK-LABEL: @hwpf2(
36; CHECK: load i32, i32* %gep, !falkor.strided.access !0
37; CHECK: load i32, i32* %gep2{{$}}
38
39; NOHWPF-LABEL: @hwpf2(
40; NOHWPF: load i32, i32* %gep{{$}}
41; NOHWPF: load i32, i32* %gep2{{$}}
42define void @hwpf2(i32* %p) {
43entry:
44  br label %loop1
45
46loop1:
47  %iv1 = phi i32 [ 0, %entry ], [ %inc1, %loop1.latch ]
48  %outer.sum = phi i32 [ 0, %entry ], [ %sum, %loop1.latch ]
49  br label %loop2.header
50
51loop2.header:
52  br label %loop2
53
54loop2:
55  %iv2 = phi i32 [ 0, %loop2.header ], [ %inc2, %loop2 ]
56  %sum = phi i32 [ %outer.sum, %loop2.header ], [ %sum.inc, %loop2 ]
57  %gep = getelementptr inbounds i32, i32* %p, i32 %iv2
58  %load = load i32, i32* %gep
59  %sum.inc = add i32 %sum, %load
60  %inc2 = add i32 %iv2, 1
61  %exitcnd2 = icmp uge i32 %inc2, 1024
62  br i1 %exitcnd2, label %exit2, label %loop2
63
64exit2:
65  %gep2 = getelementptr inbounds i32, i32* %p, i32 %iv1
66  %load2 = load i32, i32* %gep2
67  br label %loop1.latch
68
69loop1.latch:
70  %inc1 = add i32 %iv1, 1
71  %exitcnd1 = icmp uge i32 %inc1, 1024
72  br i1 %exitcnd2, label %exit, label %loop1
73
74exit:
75  ret void
76}
77
78
79; Check that non-strided load isn't marked.
80; CHECK-LABEL: @hwpf3(
81; CHECK: load i32, i32* %gep, !falkor.strided.access !0
82; CHECK: load i32, i32* %gep2{{$}}
83
84; NOHWPF-LABEL: @hwpf3(
85; NOHWPF: load i32, i32* %gep{{$}}
86; NOHWPF: load i32, i32* %gep2{{$}}
87define void @hwpf3(i32* %p, i32* %p2) {
88entry:
89  br label %loop
90
91loop:
92  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
93
94  %gep = getelementptr inbounds i32, i32* %p, i32 %iv
95  %load = load i32, i32* %gep
96
97  %gep2 = getelementptr inbounds i32, i32* %p2, i32 %load
98  %load2 = load i32, i32* %gep2
99
100  %inc = add i32 %iv, 1
101  %exitcnd = icmp uge i32 %inc, 1024
102  br i1 %exitcnd, label %exit, label %loop
103
104exit:
105  ret void
106}
107