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