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