1 ; RUN: opt -basicaa -loop-load-elim -S < %s | FileCheck %s
2 ; RUN: opt -basicaa -loop-load-elim -pgso -S < %s | FileCheck %s -check-prefix=PGSO
3 ; RUN: opt -basicaa -loop-load-elim -pgso=false -S < %s | FileCheck %s -check-prefix=NPGSO
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.
8 ; for (unsigned i = 0; i < 100; i++) {
13 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
16 define void @f(i32* %A, i32* %B, i32* %C, i64 %N) optsize {
21 for.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
25 %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
26 %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
27 %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
28 %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
30 %b = load i32, i32* %Bidx, align 4
32 store i32 %a_p1, i32* %Aidx_next, align 4
34 %a = load i32, i32* %Aidx, align 4
35 ; CHECK: %c = mul i32 %a, 2
37 store i32 %c, i32* %Cidx, align 4
39 %exitcond = icmp eq i64 %indvars.iv.next, %N
40 br i1 %exitcond, label %for.end, label %for.body
42 for.end: ; preds = %for.body
46 ; Same loop but with noalias on %A and %C. In this case load-eliminate even
50 define void @g(i32* noalias %A, i32* %B, i32* noalias %C, i64 %N) optsize {
55 for.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
59 %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
60 %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
61 %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
62 %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
64 %b = load i32, i32* %Bidx, align 4
66 store i32 %a_p1, i32* %Aidx_next, align 4
68 %a = load i32, i32* %Aidx, align 4
69 ; CHECK: %c = mul i32 %store_forwarded, 2
71 store i32 %c, i32* %Cidx, align 4
73 %exitcond = icmp eq i64 %indvars.iv.next, %N
74 br i1 %exitcond, label %for.end, label %for.body
76 for.end: ; preds = %for.body
81 ; PGSO-LABEL: @f_pgso(
82 ; NPGSO-LABEL: @f_pgso(
83 define void @f_pgso(i32* %A, i32* %B, i32* %C, i64 %N) !prof !14 {
88 for.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
92 %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
93 %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
94 %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
95 %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
97 %b = load i32, i32* %Bidx, align 4
99 store i32 %a_p1, i32* %Aidx_next, align 4
101 %a = load i32, i32* %Aidx, align 4
102 ; PGSO: %c = mul i32 %a, 2
103 ; NPGSO-NOT: %c = mul i32 %a, 2
105 store i32 %c, i32* %Cidx, align 4
107 %exitcond = icmp eq i64 %indvars.iv.next, %N
108 br i1 %exitcond, label %for.end, label %for.body
110 for.end: ; preds = %for.body
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}