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