1 ; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s
2 ; RUN: opt -aa-pipeline=basic-aa -passes=loop-load-elim -S < %s | FileCheck %s
4 target datalayout = "e-m:o-i32:64-f80:128-n8:16:32:64-S128"
7 ; Make sure loop-load-elimination triggers for a loop with uncomputable
8 ; backedge-taken counts when no runtime checks are required.
9 define void @load_elim_no_runtime_checks(ptr noalias %A, ptr noalias %B, ptr noalias %C, i32 %N) {
10 ; CHECK-LABEL: load_elim_no_runtime_checks
12 ; CHECK-NEXT: br label %for.body
17 for.body: ; preds = %for.body, %entry
18 %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
19 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
21 %Aidx_next = getelementptr inbounds i32, ptr %A, i32 %indvars.iv.next
22 %Bidx = getelementptr inbounds i32, ptr %B, i32 %indvars.iv
23 %Cidx = getelementptr inbounds i32, ptr %C, i32 %indvars.iv
24 %Aidx = getelementptr inbounds i32, ptr %A, i32 %indvars.iv
26 %b = load i32, ptr %Bidx, align 4
28 store i32 %a_p1, ptr %Aidx_next, align 4
30 %a = load i32, ptr %Aidx, align 1
32 store i32 %c, ptr %Cidx, align 4
34 %exitcond = icmp eq i32 %indvars.iv.next, %a
35 br i1 %exitcond, label %for.end, label %for.body
37 for.end: ; preds = %for.body
41 ; Make sure loop-load-elimination triggers for a loop with uncomputable
42 ; backedge-taken counts when no runtime checks are required.
43 define void @load_elim_wrapping_runtime_checks(ptr noalias %A, ptr noalias %B, ptr noalias %C, i32 %N) {
44 ; CHECK-LABEL: @load_elim_wrapping_runtime_checks
46 ; CHECK-NEXT: br label %for.body
51 for.body: ; preds = %for.body, %entry
52 %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
53 %indvars.iv.next = add i32 %indvars.iv, 1
55 %Aidx_next = getelementptr inbounds i32, ptr %A, i32 %indvars.iv.next
56 %Bidx = getelementptr inbounds i32, ptr %B, i32 %indvars.iv
57 %Cidx = getelementptr inbounds i32, ptr %C, i32 %indvars.iv
58 %Aidx = getelementptr inbounds i32, ptr %A, i32 %indvars.iv
60 %b = load i32, ptr %Bidx, align 4
62 store i32 %a_p1, ptr %Aidx_next, align 4
64 %a = load i32, ptr %Aidx, align 1
66 store i32 %c, ptr %Cidx, align 4
68 %exitcond = icmp eq i32 %indvars.iv.next, %a
69 br i1 %exitcond, label %for.end, label %for.body
71 for.end: ; preds = %for.body
75 ; Make sure we do not crash when dealing with uncomputable backedge-taken counts
76 ; and a variable distance between accesses.
77 define void @uncomputable_btc_crash(ptr %row, i32 %filter, ptr noalias %exits) local_unnamed_addr #0 {
78 ; CHECK-LABEL: @uncomputable_btc_crash
80 ; CHECK-NEXT: getelementptr
81 ; CHECK-NEXT: br label %loop
84 %add.ptr = getelementptr inbounds i8, ptr %row, i32 %filter
88 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
89 %add.ptr.gep = getelementptr i8, ptr %add.ptr, i32 %iv
90 %row.gep = getelementptr i8, ptr %row, i32 %iv
91 %l = load i8, ptr %row.gep, align 1
92 store i8 %l, ptr %add.ptr.gep, align 1
93 %iv.next = add i32 %iv, 8
94 %exit.gep = getelementptr i32, ptr %exits, i32 %iv
95 %lv = load i32, ptr %exit.gep
96 %c = icmp eq i32 %lv, 120
97 br i1 %c, label %exit, label %loop