• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -basicaa -loop-load-elim -S < %s | FileCheck %s
2
3; When optimizing for size don't eliminate in this loop because the loop would
4; have to be versioned first because A and C may alias.
5;
6;   for (unsigned i = 0; i < 100; i++) {
7;     A[i+1] = B[i] + 2;
8;     C[i] = A[i] * 2;
9;   }
10
11target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
12
13; CHECK-LABEL: @f(
14define void @f(i32* %A, i32* %B, i32* %C, i64 %N) optsize {
15
16entry:
17  br label %for.body
18
19for.body:                                         ; preds = %for.body, %entry
20  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
21  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
22
23  %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
24  %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
25  %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
26  %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
27
28  %b = load i32, i32* %Bidx, align 4
29  %a_p1 = add i32 %b, 2
30  store i32 %a_p1, i32* %Aidx_next, align 4
31
32  %a = load i32, i32* %Aidx, align 4
33; CHECK: %c = mul i32 %a, 2
34  %c = mul i32 %a, 2
35  store i32 %c, i32* %Cidx, align 4
36
37  %exitcond = icmp eq i64 %indvars.iv.next, %N
38  br i1 %exitcond, label %for.end, label %for.body
39
40for.end:                                          ; preds = %for.body
41  ret void
42}
43
44; Same loop but with noalias on %A and %C.  In this case load-eliminate even
45; with -Os.
46
47; CHECK-LABEL: @g(
48define void @g(i32* noalias %A, i32* %B, i32* noalias %C, i64 %N) optsize {
49
50entry:
51  br label %for.body
52
53for.body:                                         ; preds = %for.body, %entry
54  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
55  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
56
57  %Aidx_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
58  %Bidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
59  %Cidx = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
60  %Aidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
61
62  %b = load i32, i32* %Bidx, align 4
63  %a_p1 = add i32 %b, 2
64  store i32 %a_p1, i32* %Aidx_next, align 4
65
66  %a = load i32, i32* %Aidx, align 4
67; CHECK: %c = mul i32 %store_forwarded, 2
68  %c = mul i32 %a, 2
69  store i32 %c, i32* %Cidx, align 4
70
71  %exitcond = icmp eq i64 %indvars.iv.next, %N
72  br i1 %exitcond, label %for.end, label %for.body
73
74for.end:                                          ; preds = %for.body
75  ret void
76}
77