1; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s 2; RUN: opt -aa-pipeline=basic-aa -passes='require<profile-summary>,function(loop-load-elim)' -S < %s | FileCheck %s -check-prefix=PGSO 3; RUN: opt -passes=loop-load-elim -pgso=false -S < %s | FileCheck %s -check-prefix=NPGSO 4 5; When optimizing for size don't eliminate in this loop because the loop would 6; have to be versioned first because A and C may alias. 7; 8; for (unsigned i = 0; i < 100; i++) { 9; A[i+1] = B[i] + 2; 10; C[i] = A[i] * 2; 11; } 12 13target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 14 15; CHECK-LABEL: @f( 16define void @f(ptr %A, ptr %B, ptr %C, i64 %N) optsize { 17 18entry: 19 br label %for.body 20 21for.body: ; preds = %for.body, %entry 22 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 23 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 24 25 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next 26 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv 27 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv 28 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv 29 30 %b = load i32, ptr %Bidx, align 4 31 %a_p1 = add i32 %b, 2 32 store i32 %a_p1, ptr %Aidx_next, align 4 33 34 %a = load i32, ptr %Aidx, align 4 35; CHECK: %c = mul i32 %a, 2 36 %c = mul i32 %a, 2 37 store i32 %c, ptr %Cidx, align 4 38 39 %exitcond = icmp eq i64 %indvars.iv.next, %N 40 br i1 %exitcond, label %for.end, label %for.body 41 42for.end: ; preds = %for.body 43 ret void 44} 45 46; Same loop but with noalias on %A and %C. In this case load-eliminate even 47; with -Os. 48 49; CHECK-LABEL: @g( 50define void @g(ptr noalias %A, ptr %B, ptr noalias %C, i64 %N) optsize { 51 52entry: 53 br label %for.body 54 55for.body: ; preds = %for.body, %entry 56 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 57 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 58 59 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next 60 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv 61 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv 62 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv 63 64 %b = load i32, ptr %Bidx, align 4 65 %a_p1 = add i32 %b, 2 66 store i32 %a_p1, ptr %Aidx_next, align 4 67 68 %a = load i32, ptr %Aidx, align 4 69; CHECK: %c = mul i32 %store_forwarded, 2 70 %c = mul i32 %a, 2 71 store i32 %c, ptr %Cidx, align 4 72 73 %exitcond = icmp eq i64 %indvars.iv.next, %N 74 br i1 %exitcond, label %for.end, label %for.body 75 76for.end: ; preds = %for.body 77 ret void 78} 79 80 81; PGSO-LABEL: @f_pgso( 82; NPGSO-LABEL: @f_pgso( 83define void @f_pgso(ptr %A, ptr %B, ptr %C, i64 %N) !prof !14 { 84 85entry: 86 br label %for.body 87 88for.body: ; preds = %for.body, %entry 89 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 90 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 91 92 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next 93 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv 94 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv 95 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv 96 97 %b = load i32, ptr %Bidx, align 4 98 %a_p1 = add i32 %b, 2 99 store i32 %a_p1, ptr %Aidx_next, align 4 100 101 %a = load i32, ptr %Aidx, align 4 102; PGSO: %c = mul i32 %a, 2 103; NPGSO-NOT: %c = mul i32 %a, 2 104 %c = mul i32 %a, 2 105 store i32 %c, ptr %Cidx, align 4 106 107 %exitcond = icmp eq i64 %indvars.iv.next, %N 108 br i1 %exitcond, label %for.end, label %for.body 109 110for.end: ; preds = %for.body 111 ret void 112} 113 114!llvm.module.flags = !{!0} 115!0 = !{i32 1, !"ProfileSummary", !1} 116!1 = !{!2, !3, !4, !5, !6, !7, !8, !9} 117!2 = !{!"ProfileFormat", !"InstrProf"} 118!3 = !{!"TotalCount", i64 10000} 119!4 = !{!"MaxCount", i64 10} 120!5 = !{!"MaxInternalCount", i64 1} 121!6 = !{!"MaxFunctionCount", i64 1000} 122!7 = !{!"NumCounts", i64 3} 123!8 = !{!"NumFunctions", i64 3} 124!9 = !{!"DetailedSummary", !10} 125!10 = !{!11, !12, !13} 126!11 = !{i32 10000, i64 100, i32 1} 127!12 = !{i32 999000, i64 100, i32 1} 128!13 = !{i32 999999, i64 1, i32 2} 129!14 = !{!"function_entry_count", i64 0} 130