130 lines · plain
1; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s2; RUN: opt -aa-pipeline=basic-aa -passes='require<profile-summary>,function(loop-load-elim)' -S < %s | FileCheck %s -check-prefix=PGSO3; RUN: opt -passes=loop-load-elim -pgso=false -S < %s | FileCheck %s -check-prefix=NPGSO4 5; When optimizing for size don't eliminate in this loop because the loop would6; 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.body20 21for.body: ; preds = %for.body, %entry22 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]23 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 124 25 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next26 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv27 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv28 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv29 30 %b = load i32, ptr %Bidx, align 431 %a_p1 = add i32 %b, 232 store i32 %a_p1, ptr %Aidx_next, align 433 34 %a = load i32, ptr %Aidx, align 435; CHECK: %c = mul i32 %a, 236 %c = mul i32 %a, 237 store i32 %c, ptr %Cidx, align 438 39 %exitcond = icmp eq i64 %indvars.iv.next, %N40 br i1 %exitcond, label %for.end, label %for.body41 42for.end: ; preds = %for.body43 ret void44}45 46; Same loop but with noalias on %A and %C. In this case load-eliminate even47; 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.body54 55for.body: ; preds = %for.body, %entry56 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]57 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 158 59 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next60 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv61 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv62 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv63 64 %b = load i32, ptr %Bidx, align 465 %a_p1 = add i32 %b, 266 store i32 %a_p1, ptr %Aidx_next, align 467 68 %a = load i32, ptr %Aidx, align 469; CHECK: %c = mul i32 %store_forwarded, 270 %c = mul i32 %a, 271 store i32 %c, ptr %Cidx, align 472 73 %exitcond = icmp eq i64 %indvars.iv.next, %N74 br i1 %exitcond, label %for.end, label %for.body75 76for.end: ; preds = %for.body77 ret void78}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.body87 88for.body: ; preds = %for.body, %entry89 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]90 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 191 92 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next93 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv94 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv95 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv96 97 %b = load i32, ptr %Bidx, align 498 %a_p1 = add i32 %b, 299 store i32 %a_p1, ptr %Aidx_next, align 4100 101 %a = load i32, ptr %Aidx, align 4102; PGSO: %c = mul i32 %a, 2103; NPGSO-NOT: %c = mul i32 %a, 2104 %c = mul i32 %a, 2105 store i32 %c, ptr %Cidx, align 4106 107 %exitcond = icmp eq i64 %indvars.iv.next, %N108 br i1 %exitcond, label %for.end, label %for.body109 110for.end: ; preds = %for.body111 ret void112}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