213 lines · plain
1; RUN: opt < %s -cache-line-size=32 -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck -check-prefix=SMALLER-CACHELINE %s2; RUN: opt < %s -cache-line-size=256 -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck -check-prefix=LARGER-CACHELINE %s3 4;; This test is similar to test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll,5;; with differences that it tests the scenarios where an option for cache line size is6;; specified with different values.7 8; Check IndexedReference::computeRefCost can handle type differences between9; Stride and TripCount10 11; Round costs up to the nearest whole number i.e. in 'for.cond5' cost is calculated 12.5 and12; it makes more sense to say 13 cache lines are used rather than 12 cache lines.13 14; SMALLER-CACHELINE: Loop 'for.cond' has cost = 25615; LARGER-CACHELINE: Loop 'for.cond' has cost = 3216%struct._Handleitem = type { ptr }17 18define void @handle_to_ptr(ptr %blocks) {19; Preheader:20entry:21 br label %for.cond22 23; Loop:24for.cond: ; preds = %for.body, %entry25 %i.0 = phi i32 [ 1, %entry ], [ %inc, %for.body ]26 %cmp = icmp ult i32 %i.0, 102427 br i1 %cmp, label %for.body, label %for.end28 29for.body: ; preds = %for.cond30 %idxprom = zext i32 %i.0 to i6431 %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom32 store ptr null, ptr %arrayidx, align 833 %inc = add nuw nsw i32 %i.0, 134 br label %for.cond35 36; Exit blocks37for.end: ; preds = %for.cond38 ret void39}40 41; Check IndexedReference::computeRefCost can handle type differences between42; Coeff and ElemSize.43 44; SMALLER-CACHELINE: Loop 'for.cond' has cost = 10000000045; SMALLER-CACHELINE: Loop 'for.cond1' has cost = 100000046; SMALLER-CACHELINE: Loop 'for.cond5' has cost = 13000047; LARGER-CACHELINE: Loop 'for.cond' has cost = 10000000048; LARGER-CACHELINE: Loop 'for.cond1' has cost = 100000049; LARGER-CACHELINE: Loop 'for.cond5' has cost = 2000050@data = external dso_local global [2 x [4 x [18 x i32]]], align 151 52define dso_local void @handle_to_ptr_2(i1 %b0, i1 %b1, i1 %b2) {53entry:54 br label %for.cond55 56for.cond:57 %i.0 = phi i16 [ 0, %entry ], [ %inc18, %for.inc17 ]58 %idxprom = zext i16 %i.0 to i3259 br i1 %b2, label %for.end19, label %for.cond160 61for.cond1:62 %j.0 = phi i16 [ %inc15, %for.inc14 ], [ 0, %for.cond ]63 br i1 %b1, label %for.inc17, label %for.cond5.preheader64 65for.cond5.preheader:66 %idxprom10 = zext i16 %j.0 to i3267 br label %for.cond568 69for.cond5:70 %k.0 = phi i16 [ %inc, %for.inc ], [ 0, %for.cond5.preheader ]71 br i1 %b0, label %for.inc14, label %for.inc72 73for.inc:74 %idxprom12 = zext i16 %k.0 to i3275 %arrayidx13 = getelementptr inbounds [2 x [4 x [18 x i32]]], ptr @data, i32 0, i32 %idxprom, i32 %idxprom10, i32 %idxprom1276 store i32 7, ptr %arrayidx13, align 177 %inc = add nuw nsw i16 %k.0, 178 br label %for.cond579 80for.inc14:81 %inc15 = add nuw nsw i16 %j.0, 182 br label %for.cond183 84for.inc17:85 %inc18 = add nuw nsw i16 %i.0, 186 br label %for.cond87 88for.end19:89 ret void90}91 92; Check IndexedReference::computeRefCost can handle negative stride93 94; SMALLER-CACHELINE: Loop 'for.neg.cond' has cost = 25695; LARGER-CACHELINE: Loop 'for.neg.cond' has cost = 3296define void @handle_to_ptr_neg_stride(ptr %blocks) {97; Preheader:98entry:99 br label %for.neg.cond100 101; Loop:102for.neg.cond: ; preds = %for.neg.body, %entry103 %i.0 = phi i32 [ 1023, %entry ], [ %dec, %for.neg.body ]104 %cmp = icmp sgt i32 %i.0, 0105 br i1 %cmp, label %for.neg.body, label %for.neg.end106 107for.neg.body: ; preds = %for.neg.cond108 %idxprom = zext i32 %i.0 to i64109 %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom110 store ptr null, ptr %arrayidx, align 8111 %dec = add nsw i32 %i.0, -1112 br label %for.neg.cond113 114; Exit blocks115for.neg.end: ; preds = %for.neg.cond116 ret void117}118 119 120 121; for (int i = 40960; i > 0; i--)122; B[i] = B[40960 - i];123 124; FIXME: Currently negative access functions are treated the same as positive125; access functions. When this is fixed this testcase should have a cost126; approximately 2x higher.127 128; SMALLER-CACHELINE: Loop 'for.cond2' has cost = 10241129; LARGER-CACHELINE: Loop 'for.cond2' has cost = 1281130define void @Test2(ptr %B) {131entry:132 br label %for.cond2133 134for.cond2: ; preds = %for.body, %entry135 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]136 %cmp = icmp sgt i32 %i.0, 0137 br i1 %cmp, label %for.body, label %for.end138 139for.body: ; preds = %for.cond140 %sub = sub nsw i32 40960, %i.0141 %idxprom = sext i32 %sub to i64142 %arrayidx = getelementptr inbounds double, ptr %B, i64 %idxprom143 %0 = load double, ptr %arrayidx, align 8144 %idxprom1 = sext i32 %i.0 to i64145 %arrayidx2 = getelementptr inbounds double, ptr %B, i64 %idxprom1146 store double %0, ptr %arrayidx2, align 8147 %dec = add nsw i32 %i.0, -1148 br label %for.cond2149 150for.end: ; preds = %for.cond151 ret void152}153 154 155 156; for (i = 40960; i > 0; i--)157; C[i] = C[i];158 159; SMALLER-CACHELINE: Loop 'for.cond3' has cost = 10241160; LARGER-CACHELINE: Loop 'for.cond3' has cost = 1281161define void @Test3(ptr %C) {162entry:163 br label %for.cond3164 165for.cond3: ; preds = %for.body, %entry166 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]167 %cmp = icmp sgt i32 %i.0, 0168 br i1 %cmp, label %for.body, label %for.end169 170for.body: ; preds = %for.cond171 %idxprom = sext i32 %i.0 to i64172 %arrayidx = getelementptr inbounds ptr, ptr %C, i64 %idxprom173 %0 = load ptr, ptr %arrayidx, align 8174 %idxprom1 = sext i32 %i.0 to i64175 %arrayidx2 = getelementptr inbounds ptr, ptr %C, i64 %idxprom1176 store ptr %0, ptr %arrayidx2, align 8177 %dec = add nsw i32 %i.0, -1178 br label %for.cond3179 180for.end: ; preds = %for.cond181 ret void182}183 184 185 186; for (i = 0; i < 40960; i++)187; D[i] = D[i];188 189; SMALLER-CACHELINE: Loop 'for.cond4' has cost = 10241190; LARGER-CACHELINE: Loop 'for.cond4' has cost = 1281191define void @Test4(ptr %D) {192entry:193 br label %for.cond4194 195for.cond4: ; preds = %for.body, %entry196 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]197 %cmp = icmp slt i32 %i.0, 40960198 br i1 %cmp, label %for.body, label %for.end199 200for.body: ; preds = %for.cond201 %idxprom = sext i32 %i.0 to i64202 %arrayidx = getelementptr inbounds ptr, ptr %D, i64 %idxprom203 %0 = load ptr, ptr %arrayidx, align 8204 %idxprom1 = sext i32 %i.0 to i64205 %arrayidx2 = getelementptr inbounds ptr, ptr %D, i64 %idxprom1206 store ptr %0, ptr %arrayidx2, align 8207 %inc = add nsw i32 %i.0, 1208 br label %for.cond4209 210for.end: ; preds = %for.cond211 ret void212}213