brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.8 KiB · 2828882 Raw
293 lines · plain
1; REQUIRES: x86-registered-target2; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \3; RUN:   < %s | FileCheck %s4 5; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute,loop-vectorize' -enable-loop-distribute -force-vector-width=4 \6; RUN:   -verify-loop-info -verify-dom-info -S < %s | \7; RUN:   FileCheck --check-prefix=VECTORIZE %s8 9; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute,print<access-info>' -enable-loop-distribute \10; RUN:   -verify-loop-info -verify-dom-info -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS11 12; The memcheck version of basic.ll.  We should distribute and vectorize the13; second part of this loop with 5 memchecks (A+1 x {C, D, E} + C x {A, B})14;15;   for (i = 0; i < n; i++) {16;     A[i + 1] = A[i] * B[i];17; -------------------------------18;     C[i] = D[i] * E[i];19;   }20 21target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"22target triple = "x86_64-apple-macosx10.10.0"23 24@B = common global ptr null, align 825@A = common global ptr null, align 826@C = common global ptr null, align 827@D = common global ptr null, align 828@E = common global ptr null, align 829 30; CHECK-LABEL: @f(31define void @f() !prof !{!"function_entry_count", i32 10} {32entry:33  %a = load ptr, ptr @A, align 834  %b = load ptr, ptr @B, align 835  %c = load ptr, ptr @C, align 836  %d = load ptr, ptr @D, align 837  %e = load ptr, ptr @E, align 838  br label %for.body39 40; We have two compares for each array overlap check.41; Since the checks to A and A + 4 get merged, this will give us a42; total of 8 compares.43;44; CHECK: for.body.lver.check:45; CHECK:     = icmp46; CHECK:     = icmp47 48; CHECK:     = icmp49; CHECK:     = icmp50 51; CHECK:     = icmp52; CHECK:     = icmp53 54; CHECK:     = icmp55; CHECK:     = icmp56 57; CHECK-NOT: = icmp58; CHECK:     br i1 %conflict.rdx15, label %for.body.ph.lver.orig, label %for.body.ph.ldist1, !prof ![[PROF1:[0-9]]]59 60; The non-distributed loop that the memchecks fall back on.61 62; CHECK: for.body.ph.lver.orig:63; CHECK:     br label %for.body.lver.orig64; CHECK: for.body.lver.orig:65; CHECK:    br i1 %exitcond.lver.orig, label %for.end.loopexit, label %for.body.lver.orig66 67; Verify the two distributed loops.68 69; CHECK: for.body.ph.ldist1:70; CHECK:     br label %for.body.ldist171; CHECK: for.body.ldist1:72; CHECK:    %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist173; CHECK:    br i1 %exitcond.ldist1, label %for.body.ph, label %for.body.ldist174 75; CHECK: for.body.ph:76; CHECK:    br label %for.body77; CHECK: for.body:78; CHECK:    %mulC = mul i32 %loadD, %loadE79; CHECK: for.end:80 81 82; VECTORIZE: mul <4 x i32>83; VECTORIZE: mul <4 x i32>84; VECTORIZE-NOT: mul <4 x i32>85 86for.body:                                         ; preds = %for.body, %entry87  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]88 89  %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind90  %loadA = load i32, ptr %arrayidxA, align 491 92  %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind93  %loadB = load i32, ptr %arrayidxB, align 494 95  %mulA = mul i32 %loadB, %loadA96 97  %add = add nuw nsw i64 %ind, 198  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add99  store i32 %mulA, ptr %arrayidxA_plus_4, align 4100 101  %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind102  %loadD = load i32, ptr %arrayidxD, align 4103 104  %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind105  %loadE = load i32, ptr %arrayidxE, align 4106 107  %mulC = mul i32 %loadD, %loadE108 109  %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind110  store i32 %mulC, ptr %arrayidxC, align 4111 112  %exitcond = icmp eq i64 %add, 20113  br i1 %exitcond, label %for.end, label %for.body114 115for.end:                                          ; preds = %for.body116  ret void117}118 119; Make sure there's no "Multiple reports generated" assert with a120; volatile load, and no distribution121 122; TODO: Distribution of volatile may be possible under some123; circumstance, but the current implementation does not touch them.124 125; CHECK-LABEL: @f_volatile_load(126; CHECK: br label %for.body{{$}}127 128; CHECK-NOT: load129 130; CHECK: {{^}}for.body:131; CHECK: load i32132; CHECK: load i32133; CHECK: load volatile i32134; CHECK: load i32135; CHECK: br i1 %exitcond, label %for.end, label %for.body{{$}}136 137; CHECK-NOT: load138 139; VECTORIZE-NOT: load <4 x i32>140; VECTORIZE-NOT: mul <4 x i32>141define void @f_volatile_load() {142entry:143  %a = load ptr, ptr @A, align 8144  %b = load ptr, ptr @B, align 8145  %c = load ptr, ptr @C, align 8146  %d = load ptr, ptr @D, align 8147  %e = load ptr, ptr @E, align 8148  br label %for.body149 150for.body:151  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]152 153  %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind154  %loadA = load i32, ptr %arrayidxA, align 4155 156  %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind157  %loadB = load i32, ptr %arrayidxB, align 4158 159  %mulA = mul i32 %loadB, %loadA160 161  %add = add nuw nsw i64 %ind, 1162  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add163  store i32 %mulA, ptr %arrayidxA_plus_4, align 4164 165  %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind166  %loadD = load volatile i32, ptr %arrayidxD, align 4167 168  %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind169  %loadE = load i32, ptr %arrayidxE, align 4170 171  %mulC = mul i32 %loadD, %loadE172 173  %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind174  store i32 %mulC, ptr %arrayidxC, align 4175 176  %exitcond = icmp eq i64 %add, 20177  br i1 %exitcond, label %for.end, label %for.body178 179for.end:180  ret void181}182 183declare i32 @llvm.convergent(i32) #0184 185; This is the same as f, and would require the same bounds186; check. However, it is not OK to introduce new control dependencies187; on the convergent call.188 189; CHECK-LABEL: @f_with_convergent(190; CHECK: call i32 @llvm.convergent191; CHECK-NOT: call i32 @llvm.convergent192 193; ANALYSIS: for.body:194; ANALYSIS: Report: cannot add control dependency to convergent operation195define void @f_with_convergent() #1 {196entry:197  %a = load ptr, ptr @A, align 8198  %b = load ptr, ptr @B, align 8199  %c = load ptr, ptr @C, align 8200  %d = load ptr, ptr @D, align 8201  %e = load ptr, ptr @E, align 8202  br label %for.body203 204for.body:                                         ; preds = %for.body, %entry205  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]206 207  %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind208  %loadA = load i32, ptr %arrayidxA, align 4209 210  %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind211  %loadB = load i32, ptr %arrayidxB, align 4212 213  %mulA = mul i32 %loadB, %loadA214 215  %add = add nuw nsw i64 %ind, 1216  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add217  store i32 %mulA, ptr %arrayidxA_plus_4, align 4218 219  %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind220  %loadD = load i32, ptr %arrayidxD, align 4221 222  %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind223  %loadE = load i32, ptr %arrayidxE, align 4224 225  %convergentD = call i32 @llvm.convergent(i32 %loadD)226  %mulC = mul i32 %convergentD, %loadE227 228  %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind229  store i32 %mulC, ptr %arrayidxC, align 4230 231  %exitcond = icmp eq i64 %add, 20232  br i1 %exitcond, label %for.end, label %for.body233 234for.end:                                          ; preds = %for.body235  ret void236}237 238; Make sure an explicit request for distribution is ignored if it239; requires possibly illegal checks.240 241; CHECK-LABEL: @f_with_convergent_forced_distribute(242; CHECK: call i32 @llvm.convergent243; CHECK-NOT: call i32 @llvm.convergent244define void @f_with_convergent_forced_distribute() #1 {245entry:246  %a = load ptr, ptr @A, align 8247  %b = load ptr, ptr @B, align 8248  %c = load ptr, ptr @C, align 8249  %d = load ptr, ptr @D, align 8250  %e = load ptr, ptr @E, align 8251  br label %for.body252 253for.body:                                         ; preds = %for.body, %entry254  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]255 256  %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind257  %loadA = load i32, ptr %arrayidxA, align 4258 259  %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind260  %loadB = load i32, ptr %arrayidxB, align 4261 262  %mulA = mul i32 %loadB, %loadA263 264  %add = add nuw nsw i64 %ind, 1265  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add266  store i32 %mulA, ptr %arrayidxA_plus_4, align 4267 268  %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind269  %loadD = load i32, ptr %arrayidxD, align 4270 271  %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind272  %loadE = load i32, ptr %arrayidxE, align 4273 274  %convergentD = call i32 @llvm.convergent(i32 %loadD)275  %mulC = mul i32 %convergentD, %loadE276 277  %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind278  store i32 %mulC, ptr %arrayidxC, align 4279 280  %exitcond = icmp eq i64 %add, 20281  br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0282 283for.end:                                          ; preds = %for.body284  ret void285}286 287attributes #0 = { nounwind readnone convergent }288attributes #1 = { nounwind convergent }289 290!0 = distinct !{!0, !1}291!1 = !{!"llvm.loop.distribute.enable", i1 true}292; CHECK: ![[PROF1]] = !{!"unknown", !"loop-versioning"}293