1; RUN: opt -tbaa -basic-aa -gvn -S < %s | FileCheck %s
2; PR9971
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5
6%struct.X = type { i32, float }
7%union.vector_t = type { [2 x i64] }
8
9; Don't delete the load after the loop, because it loads values stored
10; inside the loop.
11
12; CHECK: define void @vrlh(
13
14; CHECK: for.end:
15; CHECK:   %arrayidx31 = getelementptr inbounds %union.vector_t, %union.vector_t* %t, i64 0, i32 0, i64 1
16; CHECK:   %tmp32 = load i64, i64* %arrayidx31, align 8, !tbaa [[TAG:!.*]]
17
18define void @vrlh(%union.vector_t* %va, %union.vector_t* %vb, %union.vector_t* %vd) nounwind {
19entry:
20  %t = alloca %union.vector_t, align 8
21  br label %for.body
22
23for.body:                                         ; preds = %entry, %for.body
24  %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
25  %sub = sub nsw i32 7, %i.01
26  %idxprom = sext i32 %sub to i64
27  %half = bitcast %union.vector_t* %vb to [8 x i16]*
28  %arrayidx = getelementptr inbounds [8 x i16], [8 x i16]* %half, i64 0, i64 %idxprom
29  %tmp4 = load i16, i16* %arrayidx, align 2, !tbaa !10
30  %conv = zext i16 %tmp4 to i32
31  %and = and i32 %conv, 15
32  %sub6 = sub nsw i32 7, %i.01
33  %idxprom7 = sext i32 %sub6 to i64
34  %half9 = bitcast %union.vector_t* %va to [8 x i16]*
35  %arrayidx10 = getelementptr inbounds [8 x i16], [8 x i16]* %half9, i64 0, i64 %idxprom7
36  %tmp11 = load i16, i16* %arrayidx10, align 2, !tbaa !10
37  %conv12 = zext i16 %tmp11 to i32
38  %shl = shl i32 %conv12, %and
39  %sub15 = sub nsw i32 7, %i.01
40  %idxprom16 = sext i32 %sub15 to i64
41  %half18 = bitcast %union.vector_t* %va to [8 x i16]*
42  %arrayidx19 = getelementptr inbounds [8 x i16], [8 x i16]* %half18, i64 0, i64 %idxprom16
43  %tmp20 = load i16, i16* %arrayidx19, align 2, !tbaa !10
44  %conv21 = zext i16 %tmp20 to i32
45  %sub23 = sub nsw i32 16, %and
46  %shr = lshr i32 %conv21, %sub23
47  %or = or i32 %shl, %shr
48  %conv24 = trunc i32 %or to i16
49  %sub26 = sub nsw i32 7, %i.01
50  %idxprom27 = sext i32 %sub26 to i64
51  %half28 = bitcast %union.vector_t* %t to [8 x i16]*
52  %arrayidx29 = getelementptr inbounds [8 x i16], [8 x i16]* %half28, i64 0, i64 %idxprom27
53  store i16 %conv24, i16* %arrayidx29, align 2, !tbaa !10
54  %inc = add nsw i32 %i.01, 1
55  %cmp = icmp slt i32 %inc, 8
56  br i1 %cmp, label %for.body, label %for.end
57
58for.end:                                          ; preds = %for.body
59  %arrayidx31 = getelementptr inbounds %union.vector_t, %union.vector_t* %t, i64 0, i32 0, i64 1
60  %tmp32 = load i64, i64* %arrayidx31, align 8, !tbaa !10
61  %arrayidx35 = getelementptr inbounds %union.vector_t, %union.vector_t* %vd, i64 0, i32 0, i64 1
62  store i64 %tmp32, i64* %arrayidx35, align 8, !tbaa !10
63  %arrayidx37 = getelementptr inbounds %union.vector_t, %union.vector_t* %t, i64 0, i32 0, i64 0
64  %tmp38 = load i64, i64* %arrayidx37, align 8, !tbaa !10
65  %arrayidx41 = getelementptr inbounds %union.vector_t, %union.vector_t* %vd, i64 0, i32 0, i64 0
66  store i64 %tmp38, i64* %arrayidx41, align 8, !tbaa !10
67  ret void
68}
69
70; Do delete the load after the loop.
71
72; CHECK: define i32 @test0(
73
74; CHECK:   ret i32 0
75
76define i32 @test0(%struct.X* %a) nounwind {
77entry:
78  %i = getelementptr inbounds %struct.X, %struct.X* %a, i64 0, i32 0
79  store i32 0, i32* %i, align 4, !tbaa !4
80  br label %for.body
81
82for.body:                                         ; preds = %entry, %for.body
83  %i2.01 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
84  %f = getelementptr inbounds %struct.X, %struct.X* %a, i64 %i2.01, i32 1
85  %tmp6 = load float, float* %f, align 4, !tbaa !5
86  %mul = fmul float %tmp6, 0x40019999A0000000
87  store float %mul, float* %f, align 4, !tbaa !5
88  %inc = add nsw i64 %i2.01, 1
89  %cmp = icmp slt i64 %inc, 10000
90  br i1 %cmp, label %for.body, label %for.end
91
92for.end:                                          ; preds = %for.body
93  %i9 = getelementptr inbounds %struct.X, %struct.X* %a, i64 0, i32 0
94  %tmp10 = load i32, i32* %i9, align 4, !tbaa !4
95  ret i32 %tmp10
96}
97
98; Do delete the load after the loop.
99
100; CHECK: define float @test1(
101
102; CHECK:   ret float 0x3FD3333340000000
103
104define float @test1(%struct.X* %a) nounwind {
105entry:
106  %f = getelementptr inbounds %struct.X, %struct.X* %a, i64 0, i32 1
107  store float 0x3FD3333340000000, float* %f, align 4, !tbaa !5
108  br label %for.body
109
110for.body:                                         ; preds = %entry, %for.body
111  %i.01 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
112  %i5 = getelementptr inbounds %struct.X, %struct.X* %a, i64 %i.01, i32 0
113  %tmp6 = load i32, i32* %i5, align 4, !tbaa !4
114  %mul = mul nsw i32 %tmp6, 3
115  store i32 %mul, i32* %i5, align 4, !tbaa !4
116  %inc = add nsw i64 %i.01, 1
117  %cmp = icmp slt i64 %inc, 10000
118  br i1 %cmp, label %for.body, label %for.end
119
120for.end:                                          ; preds = %for.body
121  %f9 = getelementptr inbounds %struct.X, %struct.X* %a, i64 0, i32 1
122  %tmp10 = load float, float* %f9, align 4, !tbaa !5
123  ret float %tmp10
124}
125
126; CHECK: [[TAG]] = !{[[TYPE_LL:!.*]], [[TYPE_LL]], i64 0}
127; CHECK: [[TYPE_LL]] = !{!"omnipotent char", {{!.*}}}
128!0 = !{!6, !6, i64 0}
129!1 = !{!"omnipotent char", !2}
130!2 = !{!"Simple C/C++ TBAA"}
131!3 = !{!7, !7, i64 0}
132!4 = !{!8, !8, i64 0}
133!5 = !{!9, !9, i64 0}
134!6 = !{!"short", !1}
135!7 = !{!"long long", !1}
136!8 = !{!"int", !1}
137!9 = !{!"float", !1}
138!10 = !{!1, !1, i64 0}
139