1; RUN: opt -passes=loop-distribute -enable-loop-distribute=0 -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=EXPLICIT --check-prefix=DEFAULT_OFF 2; RUN: opt -passes=loop-distribute -enable-loop-distribute=1 -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=EXPLICIT --check-prefix=DEFAULT_ON 3 4; Same loop as in basic.ll. Check that distribution is enabled/disabled 5; properly according to -enable-loop-distribute=0/1 and the 6; llvm.loop.distribute.enable metadata. 7 8define void @explicit_on(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e) { 9; CHECK-LABEL: @explicit_on( 10entry: 11 br label %for.body 12 13; EXPLICIT: for.body.ldist1: 14for.body: ; preds = %for.body, %entry 15 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ] 16 17 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind 18 %loadA = load i32, ptr %arrayidxA, align 4 19 20 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind 21 %loadB = load i32, ptr %arrayidxB, align 4 22 23 %mulA = mul i32 %loadB, %loadA 24 25 %add = add nuw nsw i64 %ind, 1 26 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add 27 store i32 %mulA, ptr %arrayidxA_plus_4, align 4 28 29 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind 30 %loadD = load i32, ptr %arrayidxD, align 4 31 32 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind 33 %loadE = load i32, ptr %arrayidxE, align 4 34 35 %mulC = mul i32 %loadD, %loadE 36 37 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind 38 store i32 %mulC, ptr %arrayidxC, align 4 39 40 %exitcond = icmp eq i64 %add, 20 41 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 42 43for.end: ; preds = %for.body 44 ret void 45} 46 47; CHECK-LABEL: @explicit_off( 48define void @explicit_off(ptr noalias %a, 49 ptr noalias %b, 50 ptr noalias %c, 51 ptr noalias %d, 52 ptr noalias %e) { 53entry: 54 br label %for.body 55 56; EXPLICIT-NOT: for.body.ldist1: 57for.body: ; preds = %for.body, %entry 58 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ] 59 60 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind 61 %loadA = load i32, ptr %arrayidxA, align 4 62 63 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind 64 %loadB = load i32, ptr %arrayidxB, align 4 65 66 %mulA = mul i32 %loadB, %loadA 67 68 %add = add nuw nsw i64 %ind, 1 69 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add 70 store i32 %mulA, ptr %arrayidxA_plus_4, align 4 71 72 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind 73 %loadD = load i32, ptr %arrayidxD, align 4 74 75 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind 76 %loadE = load i32, ptr %arrayidxE, align 4 77 78 %mulC = mul i32 %loadD, %loadE 79 80 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind 81 store i32 %mulC, ptr %arrayidxC, align 4 82 83 %exitcond = icmp eq i64 %add, 20 84 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !2 85 86for.end: ; preds = %for.body 87 ret void 88} 89 90define void @default_distribute(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, 91 ptr noalias %e) { 92; CHECK-LABEL: @default_distribute( 93entry: 94 br label %for.body 95 96; Verify the two distributed loops. 97 98; DEFAULT_ON: for.body.ldist1: 99; DEFAULT_OFF-NOT: for.body.ldist1: 100for.body: ; preds = %for.body, %entry 101 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ] 102 103 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind 104 %loadA = load i32, ptr %arrayidxA, align 4 105 106 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind 107 %loadB = load i32, ptr %arrayidxB, align 4 108 109 %mulA = mul i32 %loadB, %loadA 110 111 %add = add nuw nsw i64 %ind, 1 112 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add 113 store i32 %mulA, ptr %arrayidxA_plus_4, align 4 114 115 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind 116 %loadD = load i32, ptr %arrayidxD, align 4 117 118 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind 119 %loadE = load i32, ptr %arrayidxE, align 4 120 121 %mulC = mul i32 %loadD, %loadE 122 123 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind 124 store i32 %mulC, ptr %arrayidxC, align 4 125 126 %exitcond = icmp eq i64 %add, 20 127 br i1 %exitcond, label %for.end, label %for.body 128 129for.end: ; preds = %for.body 130 ret void 131} 132 133!0 = distinct !{!0, !1} 134!1 = !{!"llvm.loop.distribute.enable", i1 true} 135!2 = distinct !{!2, !3} 136!3 = !{!"llvm.loop.distribute.enable", i1 false} 137