1 ; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512"
4 target triple = "powerpc64le-unknown-linux-gnu"
6 ; CHECK: Loop 'for.j' has cost = 201000000
7 ; CHECK-NEXT: Loop 'for.i' has cost = 102000000
8 ; CHECK-NEXT: Loop 'for.k' has cost = 120000
10 ;; Test to make sure when we have multiple conflicting access patterns, the
11 ;; chosen loop configuration favours the majority of those accesses.
12 ;; For example this nest should be ordered as j-i-k.
13 ;; for (int i = 0; i < n; i++)
14 ;; for (int j = 0; j < n; j++)
15 ;; for (int k = 0; k < n; k++) {
21 define void @foo(i32 noundef signext %n, ptr noalias noundef %A, ptr noalias noundef %B, ptr noalias noundef %C) {
23 %0 = zext i32 %n to i64
24 %1 = zext i32 %n to i64
25 %2 = zext i32 %n to i64
26 %3 = zext i32 %n to i64
27 %4 = zext i32 %n to i64
28 %5 = zext i32 %n to i64
29 %cmp5 = icmp sgt i32 %n, 0
30 br i1 %cmp5, label %for.i.preheader, label %for.end30
32 for.i.preheader: ; preds = %entry
33 %wide.trip.count16 = zext i32 %n to i64
36 for.i: ; preds = %for.i.preheader, %for.inc28
37 %indvars.iv13 = phi i64 [ 0, %for.i.preheader ], [ %indvars.iv.next14, %for.inc28 ]
38 %cmp23 = icmp sgt i32 %n, 0
39 br i1 %cmp23, label %for.j.preheader, label %for.inc28
41 for.j.preheader: ; preds = %for.i
42 %wide.trip.count11 = zext i32 %n to i64
45 for.j: ; preds = %for.j.preheader, %for.inc25
46 %indvars.iv8 = phi i64 [ 0, %for.j.preheader ], [ %indvars.iv.next9, %for.inc25 ]
47 %cmp61 = icmp sgt i32 %n, 0
48 br i1 %cmp61, label %for.k.preheader, label %for.inc25
50 for.k.preheader: ; preds = %for.j
51 %wide.trip.count = zext i32 %n to i64
54 for.k: ; preds = %for.k.preheader, %for.k
55 %indvars.iv = phi i64 [ 0, %for.k.preheader ], [ %indvars.iv.next, %for.k ]
56 %6 = mul nuw i64 %0, %1
57 %7 = mul nsw i64 %6, %indvars.iv13
58 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %7
59 %8 = mul nuw nsw i64 %indvars.iv8, %1
60 %arrayidx10 = getelementptr inbounds i32, ptr %arrayidx, i64 %8
61 %arrayidx12 = getelementptr inbounds i32, ptr %arrayidx10, i64 %indvars.iv
62 store i32 1, ptr %arrayidx12, align 4
63 %9 = mul nuw i64 %2, %3
64 %10 = mul nsw i64 %9, %indvars.iv8
65 %arrayidx14 = getelementptr inbounds i32, ptr %B, i64 %10
66 %11 = mul nuw nsw i64 %indvars.iv13, %3
67 %arrayidx16 = getelementptr inbounds i32, ptr %arrayidx14, i64 %11
68 %arrayidx18 = getelementptr inbounds i32, ptr %arrayidx16, i64 %indvars.iv
69 store i32 2, ptr %arrayidx18, align 4
70 %12 = mul nuw i64 %4, %5
71 %13 = mul nsw i64 %12, %indvars.iv8
72 %arrayidx20 = getelementptr inbounds i32, ptr %C, i64 %13
73 %14 = mul nuw nsw i64 %indvars.iv13, %5
74 %arrayidx22 = getelementptr inbounds i32, ptr %arrayidx20, i64 %14
75 %arrayidx24 = getelementptr inbounds i32, ptr %arrayidx22, i64 %indvars.iv
76 store i32 3, ptr %arrayidx24, align 4
77 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
78 %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
79 br i1 %exitcond, label %for.k, label %for.inc25.loopexit
81 for.inc25.loopexit: ; preds = %for.k
84 for.inc25: ; preds = %for.inc25.loopexit, %for.j
85 %indvars.iv.next9 = add nuw nsw i64 %indvars.iv8, 1
86 %exitcond12 = icmp ne i64 %indvars.iv.next9, %wide.trip.count11
87 br i1 %exitcond12, label %for.j, label %for.inc28.loopexit
89 for.inc28.loopexit: ; preds = %for.inc25
92 for.inc28: ; preds = %for.inc28.loopexit, %for.i
93 %indvars.iv.next14 = add nuw nsw i64 %indvars.iv13, 1
94 %exitcond17 = icmp ne i64 %indvars.iv.next14, %wide.trip.count16
95 br i1 %exitcond17, label %for.i, label %for.end30.loopexit
97 for.end30.loopexit: ; preds = %for.inc28
100 for.end30: ; preds = %for.end30.loopexit, %entry