113 lines · plain
1; RUN: opt -passes=instcombine -S < %s | FileCheck %s2;3; void func(long n, double A[static const restrict n]) {4; for (int i = 0; i < n; i+=1)5; for (int j = 0; j < n;j+=1)6; for (int k = 0; k < n; k += 1)7; for (int l = 0; l < n; l += 1) {8; ptr p = &A[i + j + k + l];9; double x = *p;10; double y = *p;11; arg(x + y);12; }13; }14;15; Check that the original access group on %0 is preserved when replacing uses16; of %1 with it, as %0 is not moved and if %0 would not be parallel in the17; original loop it would be UB.18;19target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"20 21declare void @arg(double)22 23define void @func(i64 %n, ptr noalias nonnull %A) {24entry:25 br label %for.cond26 27for.cond:28 %i.0 = phi i32 [ 0, %entry ], [ %add31, %for.inc30 ]29 %conv = sext i32 %i.0 to i6430 %cmp = icmp slt i64 %conv, %n31 br i1 %cmp, label %for.cond2, label %for.end3232 33for.cond2:34 %j.0 = phi i32 [ %add28, %for.inc27 ], [ 0, %for.cond ]35 %conv3 = sext i32 %j.0 to i6436 %cmp4 = icmp slt i64 %conv3, %n37 br i1 %cmp4, label %for.cond8, label %for.inc3038 39for.cond8:40 %k.0 = phi i32 [ %add25, %for.inc24 ], [ 0, %for.cond2 ]41 %conv9 = sext i32 %k.0 to i6442 %cmp10 = icmp slt i64 %conv9, %n43 br i1 %cmp10, label %for.cond14, label %for.inc2744 45for.cond14:46 %l.0 = phi i32 [ %add23, %for.body19 ], [ 0, %for.cond8 ]47 %conv15 = sext i32 %l.0 to i6448 %cmp16 = icmp slt i64 %conv15, %n49 br i1 %cmp16, label %for.body19, label %for.inc2450 51for.body19:52 %add = add nsw i32 %i.0, %j.053 %add20 = add nsw i32 %add, %k.054 %add21 = add nsw i32 %add20, %l.055 %idxprom = sext i32 %add21 to i6456 %arrayidx = getelementptr inbounds double, ptr %A, i64 %idxprom57 %0 = load double, ptr %arrayidx, align 8, !llvm.access.group !158 %1 = load double, ptr %arrayidx, align 8, !llvm.access.group !259 %add22 = fadd double %0, %160 call void @arg(double %add22), !llvm.access.group !361 %add23 = add nsw i32 %l.0, 162 br label %for.cond14, !llvm.loop !1163 64for.inc24:65 %add25 = add nsw i32 %k.0, 166 br label %for.cond8, !llvm.loop !1467 68for.inc27:69 %add28 = add nsw i32 %j.0, 170 br label %for.cond2, !llvm.loop !1671 72for.inc30:73 %add31 = add nsw i32 %i.0, 174 br label %for.cond, !llvm.loop !1875 76for.end32:77 ret void78}79 80 81; access groups82!7 = distinct !{}83!8 = distinct !{}84!9 = distinct !{}85 86; access group lists87!1 = !{!7, !9}88!2 = !{!7, !8}89!3 = !{!7, !8, !9}90 91!11 = distinct !{!11, !13}92!13 = !{!"llvm.loop.parallel_accesses", !7}93 94!14 = distinct !{!14, !15}95!15 = !{!"llvm.loop.parallel_accesses", !8}96 97!16 = distinct !{!16, !17}98!17 = !{!"llvm.loop.parallel_accesses", !8, !9}99 100!18 = distinct !{!18, !19}101!19 = !{!"llvm.loop.parallel_accesses", !9}102 103 104; CHECK: load double, {{.*}} !llvm.access.group ![[ACCESSGROUP_0:[0-9]+]]105; CHECK: br label %for.cond14, !llvm.loop ![[LOOP_4:[0-9]+]]106 107; CHECK: ![[ACCESSGROUP_0]] = !{![[G1:[0-9]+]], ![[G2:[0-9]+]]}108; CHECK: ![[G1]] = distinct !{}109; CHECK: ![[G2]] = distinct !{}110 111; CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[PARALLEL_ACCESSES_5:[0-9]+]]}112; CHECK: ![[PARALLEL_ACCESSES_5]] = !{!"llvm.loop.parallel_accesses", ![[G1]]}113