brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.4 KiB · 9aa0484 Raw
155 lines · plain
1; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s2 3target datalayout = "e-m:e-i64:64-n32:64"4target triple = "powerpc64le-unknown-linux-gnu"5 6; void foo(long n, long m, long o, int A[n][m][o]) {7;   for (long i = 0; i < n; i++)8;     for (long j = 0; j < m; j++)9;       for (long k = 0; k < o; k++)10;         A[2*i+3][3*j-4][2*k+7] = 1;11; }12 13; CHECK: Loop 'for.i' has cost = 10000000014; CHECK-NEXT: Loop 'for.j' has cost = 100000015; CHECK-NEXT: Loop 'for.k' has cost = 7000016 17define void @foo(i64 %n, i64 %m, i64 %o, ptr %A) {18entry:19  %cmp32 = icmp sgt i64 %n, 020  %cmp230 = icmp sgt i64 %m, 021  %cmp528 = icmp sgt i64 %o, 022  br i1 %cmp32, label %for.cond1.preheader.lr.ph, label %for.end23 24for.cond1.preheader.lr.ph:                        ; preds = %entry25  br i1 %cmp230, label %for.i.preheader, label %for.end26 27for.i.preheader:                                  ; preds = %for.cond1.preheader.lr.ph28  br i1 %cmp528, label %for.i.preheader.split, label %for.end29 30for.i.preheader.split:                            ; preds = %for.i.preheader31  br label %for.i32 33for.i:                                            ; preds = %for.inci, %for.i.preheader.split34  %i = phi i64 [ %inci, %for.inci ], [ 0, %for.i.preheader.split ]35  %mul8 = shl i64 %i, 136  %add9 = add nsw i64 %mul8, 337  %0 = mul i64 %add9, %m38  %sub = add i64 %0, -439  br label %for.j40 41for.j:                                            ; preds = %for.incj, %for.i42  %j = phi i64 [ %incj, %for.incj ], [ 0, %for.i ]43  %mul7 = mul nsw i64 %j, 344  %tmp = add i64 %sub, %mul745  %tmp27 = mul i64 %tmp, %o46  br label %for.k47 48for.k:                                            ; preds = %for.k, %for.j.us49  %k = phi i64 [ 0, %for.j ], [ %inck, %for.k ]50 51  %mul = mul nsw i64 %k, 252  %arrayidx.sum = add i64 %mul, 753  %arrayidx10.sum = add i64 %arrayidx.sum, %tmp2754  %arrayidx11 = getelementptr inbounds i32, ptr %A, i64 %arrayidx10.sum55  store i32 1, ptr %arrayidx11, align 456 57  %inck = add nsw i64 %k, 158  %exitcond.us = icmp eq i64 %inck, %o59  br i1 %exitcond.us, label %for.incj, label %for.k60 61for.incj:                                         ; preds = %for.k62  %incj = add nsw i64 %j, 163  %exitcond54.us = icmp eq i64 %incj, %m64  br i1 %exitcond54.us, label %for.inci, label %for.j65 66for.inci:                                         ; preds = %for.incj67  %inci = add nsw i64 %i, 168  %exitcond55.us = icmp eq i64 %inci, %n69  br i1 %exitcond55.us, label %for.end.loopexit, label %for.i70 71for.end.loopexit:                                 ; preds = %for.inci72  br label %for.end73 74for.end:                                          ; preds = %for.end.loopexit, %for.cond1.preheader.lr.ph, %entry75  ret void76}77 78; Loop i is supposed to have the largest cost and be placed79; as the outermost loop. This test differs from foo() since the80; loopnest has a suboptimal order j-i-k.81; After D123400 we ensure that the order of loop cache analysis output82; is loop i-j-k, despite the suboptimal order in the original loopnest.83;84; void foo(long n, long m, long o, int A[n][m][o]) {85;   for (long j = 0; j < m; j++)86;     for (long i = 0; i < n; i++)87;       for (long k = 0; k < o; k++)88;         A[2*i+3][2*j-4][2*k+7] = 1;89; }90 91; CHECK: Loop 'for.i' has cost = 10000000092; CHECK-NEXT: Loop 'for.j' has cost = 100000093; CHECK-NEXT: Loop 'for.k' has cost = 7000094 95define void @foo2(i64 %n, i64 %m, i64 %o, ptr %A) {96entry:97  %cmp32 = icmp sgt i64 %n, 098  %cmp230 = icmp sgt i64 %m, 099  %cmp528 = icmp sgt i64 %o, 0100  br i1 %cmp32, label %for.cond1.preheader.lr.ph, label %for.end101 102for.cond1.preheader.lr.ph:                        ; preds = %entry103  br i1 %cmp230, label %for.j.preheader, label %for.end104 105for.j.preheader:                                  ; preds = %for.cond1.preheader.lr.ph106  br i1 %cmp528, label %for.j.preheader.split, label %for.end107 108for.j.preheader.split:                            ; preds = %for.j.preheader109  br label %for.j110 111for.i:                                            ; preds = %for.inci, %for.j112  %i = phi i64 [ %inci, %for.inci ], [ 0, %for.j ]113  %mul8 = shl i64 %i, 1114  %add9 = add nsw i64 %mul8, 3115  %0 = mul i64 %add9, %m116  %sub = add i64 %0, -4117  %mul7 = mul nsw i64 %j, 2118  %tmp = add i64 %sub, %mul7119  %tmp27 = mul i64 %tmp, %o120  br label %for.k121 122for.j:                                            ; preds = %for.incj, %for.j.preheader.split123  %j = phi i64 [ %incj, %for.incj ], [ 0, %for.j.preheader.split ]124  br label %for.i125 126for.k:                                            ; preds = %for.k, %for.i127  %k = phi i64 [ 0, %for.i ], [ %inck, %for.k ]128 129  %mul = mul nsw i64 %k, 2130  %arrayidx.sum = add i64 %mul, 7131  %arrayidx10.sum = add i64 %arrayidx.sum, %tmp27132  %arrayidx11 = getelementptr inbounds i32, ptr %A, i64 %arrayidx10.sum133  store i32 1, ptr %arrayidx11, align 4134 135  %inck = add nsw i64 %k, 1136  %exitcond.us = icmp eq i64 %inck, %o137  br i1 %exitcond.us, label %for.inci, label %for.k138 139for.incj:                                         ; preds = %for.inci140  %incj = add nsw i64 %j, 1141  %exitcond54.us = icmp eq i64 %incj, %m142  br i1 %exitcond54.us, label %for.end.loopexit, label %for.j143 144for.inci:                                         ; preds = %for.k145  %inci = add nsw i64 %i, 1146  %exitcond55.us = icmp eq i64 %inci, %n147  br i1 %exitcond55.us, label %for.incj, label %for.i148 149for.end.loopexit:                                 ; preds = %for.incj150  br label %for.end151 152for.end:                                          ; preds = %for.end.loopexit, %for.cond1.preheader.lr.ph, %entry153  ret void154}155