203 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; Check IndexedReference::computeRefCost can handle type differences between7; Stride and TripCount8 9; CHECK: Loop 'for.cond' has cost = 6410 11%struct._Handleitem = type { ptr }12 13define void @handle_to_ptr(ptr %blocks) {14; Preheader:15entry:16 br label %for.cond17 18; Loop:19for.cond: ; preds = %for.body, %entry20 %i.0 = phi i32 [ 1, %entry ], [ %inc, %for.body ]21 %cmp = icmp ult i32 %i.0, 102422 br i1 %cmp, label %for.body, label %for.end23 24for.body: ; preds = %for.cond25 %idxprom = zext i32 %i.0 to i6426 %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom27 store ptr null, ptr %arrayidx, align 828 %inc = add nuw nsw i32 %i.0, 129 br label %for.cond30 31; Exit blocks32for.end: ; preds = %for.cond33 ret void34}35 36; Check IndexedReference::computeRefCost can handle type differences between37; Coeff and ElemSize.38 39; CHECK: Loop 'for.cond' has cost = 10000000040; CHECK: Loop 'for.cond1' has cost = 100000041; CHECK: Loop 'for.cond5' has cost = 4000042 43@data = external dso_local global [2 x [4 x [18 x i32]]], align 144 45define dso_local void @handle_to_ptr_2(i1 %b0, i1 %b1, i1 %b2) {46entry:47 br label %for.cond48 49for.cond:50 %i.0 = phi i16 [ 0, %entry ], [ %inc18, %for.inc17 ]51 %idxprom = zext i16 %i.0 to i3252 br i1 %b2, label %for.end19, label %for.cond153 54for.cond1:55 %j.0 = phi i16 [ %inc15, %for.inc14 ], [ 0, %for.cond ]56 br i1 %b1, label %for.inc17, label %for.cond5.preheader57 58for.cond5.preheader:59 %idxprom10 = zext i16 %j.0 to i3260 br label %for.cond561 62for.cond5:63 %k.0 = phi i16 [ %inc, %for.inc ], [ 0, %for.cond5.preheader ]64 br i1 %b0, label %for.inc14, label %for.inc65 66for.inc:67 %idxprom12 = zext i16 %k.0 to i3268 %arrayidx13 = getelementptr inbounds [2 x [4 x [18 x i32]]], ptr @data, i32 0, i32 %idxprom, i32 %idxprom10, i32 %idxprom1269 store i32 7, ptr %arrayidx13, align 170 %inc = add nuw nsw i16 %k.0, 171 br label %for.cond572 73for.inc14:74 %inc15 = add nuw nsw i16 %j.0, 175 br label %for.cond176 77for.inc17:78 %inc18 = add nuw nsw i16 %i.0, 179 br label %for.cond80 81for.end19:82 ret void83}84 85; Check IndexedReference::computeRefCost can handle negative stride86 87; CHECK: Loop 'for.neg.cond' has cost = 6488 89define void @handle_to_ptr_neg_stride(ptr %blocks) {90; Preheader:91entry:92 br label %for.neg.cond93 94; Loop:95for.neg.cond: ; preds = %for.neg.body, %entry96 %i.0 = phi i32 [ 1023, %entry ], [ %dec, %for.neg.body ]97 %cmp = icmp sgt i32 %i.0, 098 br i1 %cmp, label %for.neg.body, label %for.neg.end99 100for.neg.body: ; preds = %for.neg.cond101 %idxprom = zext i32 %i.0 to i64102 %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom103 store ptr null, ptr %arrayidx, align 8104 %dec = add nsw i32 %i.0, -1105 br label %for.neg.cond106 107; Exit blocks108for.neg.end: ; preds = %for.neg.cond109 ret void110}111 112 113 114; for (int i = 40960; i > 0; i--)115; B[i] = B[40960 - i];116 117; FIXME: Currently negative access functions are treated the same as positive118; access functions. When this is fixed this testcase should have a cost119; approximately 2x higher.120 121; CHECK: Loop 'for.cond2' has cost = 2561122define void @Test2(ptr %B) {123entry:124 br label %for.cond2125 126for.cond2: ; preds = %for.body, %entry127 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]128 %cmp = icmp sgt i32 %i.0, 0129 br i1 %cmp, label %for.body, label %for.end130 131for.body: ; preds = %for.cond132 %sub = sub nsw i32 40960, %i.0133 %idxprom = sext i32 %sub to i64134 %arrayidx = getelementptr inbounds double, ptr %B, i64 %idxprom135 %0 = load double, ptr %arrayidx, align 8136 %idxprom1 = sext i32 %i.0 to i64137 %arrayidx2 = getelementptr inbounds double, ptr %B, i64 %idxprom1138 store double %0, ptr %arrayidx2, align 8139 %dec = add nsw i32 %i.0, -1140 br label %for.cond2141 142for.end: ; preds = %for.cond143 ret void144}145 146 147 148; for (i = 40960; i > 0; i--)149; C[i] = C[i];150 151; CHECK: Loop 'for.cond3' has cost = 2561152define void @Test3(ptr %C) {153entry:154 br label %for.cond3155 156for.cond3: ; preds = %for.body, %entry157 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]158 %cmp = icmp sgt i32 %i.0, 0159 br i1 %cmp, label %for.body, label %for.end160 161for.body: ; preds = %for.cond162 %idxprom = sext i32 %i.0 to i64163 %arrayidx = getelementptr inbounds ptr, ptr %C, i64 %idxprom164 %0 = load ptr, ptr %arrayidx, align 8165 %idxprom1 = sext i32 %i.0 to i64166 %arrayidx2 = getelementptr inbounds ptr, ptr %C, i64 %idxprom1167 store ptr %0, ptr %arrayidx2, align 8168 %dec = add nsw i32 %i.0, -1169 br label %for.cond3170 171for.end: ; preds = %for.cond172 ret void173}174 175 176 177; for (i = 0; i < 40960; i++)178; D[i] = D[i];179 180; CHECK: Loop 'for.cond4' has cost = 2561181define void @Test4(ptr %D) {182entry:183 br label %for.cond4184 185for.cond4: ; preds = %for.body, %entry186 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]187 %cmp = icmp slt i32 %i.0, 40960188 br i1 %cmp, label %for.body, label %for.end189 190for.body: ; preds = %for.cond191 %idxprom = sext i32 %i.0 to i64192 %arrayidx = getelementptr inbounds ptr, ptr %D, i64 %idxprom193 %0 = load ptr, ptr %arrayidx, align 8194 %idxprom1 = sext i32 %i.0 to i64195 %arrayidx2 = getelementptr inbounds ptr, ptr %D, i64 %idxprom1196 store ptr %0, ptr %arrayidx2, align 8197 %inc = add nsw i32 %i.0, 1198 br label %for.cond4199 200for.end: ; preds = %for.cond201 ret void202}203