1; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s 2 3target datalayout = "e-m:e-i64:64-n32:64" 4target triple = "powerpc64le-unknown-linux-gnu" 5 6; Check IndexedReference::computeRefCost can handle type differences between 7; Stride and TripCount 8 9; CHECK: Loop 'for.cond' has cost = 64 10 11%struct._Handleitem = type { %struct._Handleitem* } 12 13define void @handle_to_ptr(%struct._Handleitem** %blocks) { 14; Preheader: 15entry: 16 br label %for.cond 17 18; Loop: 19for.cond: ; preds = %for.body, %entry 20 %i.0 = phi i32 [ 1, %entry ], [ %inc, %for.body ] 21 %cmp = icmp ult i32 %i.0, 1024 22 br i1 %cmp, label %for.body, label %for.end 23 24for.body: ; preds = %for.cond 25 %idxprom = zext i32 %i.0 to i64 26 %arrayidx = getelementptr inbounds %struct._Handleitem*, %struct._Handleitem** %blocks, i64 %idxprom 27 store %struct._Handleitem* null, %struct._Handleitem** %arrayidx, align 8 28 %inc = add nuw nsw i32 %i.0, 1 29 br label %for.cond 30 31; Exit blocks 32for.end: ; preds = %for.cond 33 ret void 34} 35 36 37 38; Check IndexedReference::computeRefCost can handle negative stride 39 40; CHECK: Loop 'for.neg.cond' has cost = 64 41 42define void @handle_to_ptr_neg_stride(%struct._Handleitem** %blocks) { 43; Preheader: 44entry: 45 br label %for.neg.cond 46 47; Loop: 48for.neg.cond: ; preds = %for.neg.body, %entry 49 %i.0 = phi i32 [ 1023, %entry ], [ %dec, %for.neg.body ] 50 %cmp = icmp sgt i32 %i.0, 0 51 br i1 %cmp, label %for.neg.body, label %for.neg.end 52 53for.neg.body: ; preds = %for.neg.cond 54 %idxprom = zext i32 %i.0 to i64 55 %arrayidx = getelementptr inbounds %struct._Handleitem*, %struct._Handleitem** %blocks, i64 %idxprom 56 store %struct._Handleitem* null, %struct._Handleitem** %arrayidx, align 8 57 %dec = add nsw i32 %i.0, -1 58 br label %for.neg.cond 59 60; Exit blocks 61for.neg.end: ; preds = %for.neg.cond 62 ret void 63} 64 65 66 67; for (int i = 40960; i > 0; i--) 68; B[i] = B[40960 - i]; 69 70; FIXME: Currently negative access functions are treated the same as positive 71; access functions. When this is fixed this testcase should have a cost 72; approximately 2x higher. 73 74; CHECK: Loop 'for.cond2' has cost = 2560 75define void @Test2(double* %B) { 76entry: 77 br label %for.cond2 78 79for.cond2: ; preds = %for.body, %entry 80 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ] 81 %cmp = icmp sgt i32 %i.0, 0 82 br i1 %cmp, label %for.body, label %for.end 83 84for.body: ; preds = %for.cond 85 %sub = sub nsw i32 40960, %i.0 86 %idxprom = sext i32 %sub to i64 87 %arrayidx = getelementptr inbounds double, double* %B, i64 %idxprom 88 %0 = load double, double* %arrayidx, align 8 89 %idxprom1 = sext i32 %i.0 to i64 90 %arrayidx2 = getelementptr inbounds double, double* %B, i64 %idxprom1 91 store double %0, double* %arrayidx2, align 8 92 %dec = add nsw i32 %i.0, -1 93 br label %for.cond2 94 95for.end: ; preds = %for.cond 96 ret void 97} 98 99 100 101; for (i = 40960; i > 0; i--) 102; C[i] = C[i]; 103 104; CHECK: Loop 'for.cond3' has cost = 2560 105define void @Test3(double** %C) { 106entry: 107 br label %for.cond3 108 109for.cond3: ; preds = %for.body, %entry 110 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ] 111 %cmp = icmp sgt i32 %i.0, 0 112 br i1 %cmp, label %for.body, label %for.end 113 114for.body: ; preds = %for.cond 115 %idxprom = sext i32 %i.0 to i64 116 %arrayidx = getelementptr inbounds double*, double** %C, i64 %idxprom 117 %0 = load double*, double** %arrayidx, align 8 118 %idxprom1 = sext i32 %i.0 to i64 119 %arrayidx2 = getelementptr inbounds double*, double** %C, i64 %idxprom1 120 store double* %0, double** %arrayidx2, align 8 121 %dec = add nsw i32 %i.0, -1 122 br label %for.cond3 123 124for.end: ; preds = %for.cond 125 ret void 126} 127 128 129 130; for (i = 0; i < 40960; i++) 131; D[i] = D[i]; 132 133; CHECK: Loop 'for.cond4' has cost = 2560 134define void @Test4(double** %D) { 135entry: 136 br label %for.cond4 137 138for.cond4: ; preds = %for.body, %entry 139 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 140 %cmp = icmp slt i32 %i.0, 40960 141 br i1 %cmp, label %for.body, label %for.end 142 143for.body: ; preds = %for.cond 144 %idxprom = sext i32 %i.0 to i64 145 %arrayidx = getelementptr inbounds double*, double** %D, i64 %idxprom 146 %0 = load double*, double** %arrayidx, align 8 147 %idxprom1 = sext i32 %i.0 to i64 148 %arrayidx2 = getelementptr inbounds double*, double** %D, i64 %idxprom1 149 store double* %0, double** %arrayidx2, align 8 150 %inc = add nsw i32 %i.0, 1 151 br label %for.cond4 152 153for.end: ; preds = %for.cond 154 ret void 155} 156