xref: /llvm-project/llvm/test/Analysis/TypeBasedAliasAnalysis/dynamic-indices.ll (revision 6402fc22e1bccd0984beadfe931511175bac688c)
1; RUN: opt -aa-pipeline=tbaa,basic-aa -passes=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, ptr %t, i64 0, i32 0, i64 1
16; CHECK:   %tmp32 = load i64, ptr %arrayidx31, align 8, !tbaa [[TAG:!.*]]
17
18define void @vrlh(ptr %va, ptr %vb, ptr %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  %arrayidx = getelementptr inbounds [8 x i16], ptr %vb, i64 0, i64 %idxprom
28  %tmp4 = load i16, ptr %arrayidx, align 2, !tbaa !10
29  %conv = zext i16 %tmp4 to i32
30  %and = and i32 %conv, 15
31  %sub6 = sub nsw i32 7, %i.01
32  %idxprom7 = sext i32 %sub6 to i64
33  %arrayidx10 = getelementptr inbounds [8 x i16], ptr %va, i64 0, i64 %idxprom7
34  %tmp11 = load i16, ptr %arrayidx10, align 2, !tbaa !10
35  %conv12 = zext i16 %tmp11 to i32
36  %shl = shl i32 %conv12, %and
37  %sub15 = sub nsw i32 7, %i.01
38  %idxprom16 = sext i32 %sub15 to i64
39  %arrayidx19 = getelementptr inbounds [8 x i16], ptr %va, i64 0, i64 %idxprom16
40  %tmp20 = load i16, ptr %arrayidx19, align 2, !tbaa !10
41  %conv21 = zext i16 %tmp20 to i32
42  %sub23 = sub nsw i32 16, %and
43  %shr = lshr i32 %conv21, %sub23
44  %or = or i32 %shl, %shr
45  %conv24 = trunc i32 %or to i16
46  %sub26 = sub nsw i32 7, %i.01
47  %idxprom27 = sext i32 %sub26 to i64
48  %arrayidx29 = getelementptr inbounds [8 x i16], ptr %t, i64 0, i64 %idxprom27
49  store i16 %conv24, ptr %arrayidx29, align 2, !tbaa !10
50  %inc = add nsw i32 %i.01, 1
51  %cmp = icmp slt i32 %inc, 8
52  br i1 %cmp, label %for.body, label %for.end
53
54for.end:                                          ; preds = %for.body
55  %arrayidx31 = getelementptr inbounds %union.vector_t, ptr %t, i64 0, i32 0, i64 1
56  %tmp32 = load i64, ptr %arrayidx31, align 8, !tbaa !10
57  %arrayidx35 = getelementptr inbounds %union.vector_t, ptr %vd, i64 0, i32 0, i64 1
58  store i64 %tmp32, ptr %arrayidx35, align 8, !tbaa !10
59  %tmp38 = load i64, ptr %t, align 8, !tbaa !10
60  store i64 %tmp38, ptr %vd, align 8, !tbaa !10
61  ret void
62}
63
64; Do delete the load after the loop.
65
66; CHECK: define i32 @test0(
67
68; CHECK:   ret i32 0
69
70define i32 @test0(ptr %a) nounwind {
71entry:
72  store i32 0, ptr %a, align 4, !tbaa !4
73  br label %for.body
74
75for.body:                                         ; preds = %entry, %for.body
76  %i2.01 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
77  %f = getelementptr inbounds %struct.X, ptr %a, i64 %i2.01, i32 1
78  %tmp6 = load float, ptr %f, align 4, !tbaa !5
79  %mul = fmul float %tmp6, 0x40019999A0000000
80  store float %mul, ptr %f, align 4, !tbaa !5
81  %inc = add nsw i64 %i2.01, 1
82  %cmp = icmp slt i64 %inc, 10000
83  br i1 %cmp, label %for.body, label %for.end
84
85for.end:                                          ; preds = %for.body
86  %tmp10 = load i32, ptr %a, align 4, !tbaa !4
87  ret i32 %tmp10
88}
89
90; Do delete the load after the loop.
91
92; CHECK: define float @test1(
93
94; CHECK:   ret float 0x3FD3333340000000
95
96define float @test1(ptr %a) nounwind {
97entry:
98  %f = getelementptr inbounds %struct.X, ptr %a, i64 0, i32 1
99  store float 0x3FD3333340000000, ptr %f, align 4, !tbaa !5
100  br label %for.body
101
102for.body:                                         ; preds = %entry, %for.body
103  %i.01 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
104  %i5 = getelementptr inbounds %struct.X, ptr %a, i64 %i.01, i32 0
105  %tmp6 = load i32, ptr %i5, align 4, !tbaa !4
106  %mul = mul nsw i32 %tmp6, 3
107  store i32 %mul, ptr %i5, align 4, !tbaa !4
108  %inc = add nsw i64 %i.01, 1
109  %cmp = icmp slt i64 %inc, 10000
110  br i1 %cmp, label %for.body, label %for.end
111
112for.end:                                          ; preds = %for.body
113  %f9 = getelementptr inbounds %struct.X, ptr %a, i64 0, i32 1
114  %tmp10 = load float, ptr %f9, align 4, !tbaa !5
115  ret float %tmp10
116}
117
118; CHECK: [[TAG]] = !{[[TYPE_LL:!.*]], [[TYPE_LL]], i64 0}
119; CHECK: [[TYPE_LL]] = !{!"omnipotent char", {{!.*}}}
120!0 = !{!6, !6, i64 0}
121!1 = !{!"omnipotent char", !2}
122!2 = !{!"Simple C/C++ TBAA"}
123!3 = !{!7, !7, i64 0}
124!4 = !{!8, !8, i64 0}
125!5 = !{!9, !9, i64 0}
126!6 = !{!"short", !1}
127!7 = !{!"long long", !1}
128!8 = !{!"int", !1}
129!9 = !{!"float", !1}
130!10 = !{!1, !1, i64 0}
131