1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
5 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 %struct.S = type { i32, double, ptr, i32 }
16 ; static const struct S GlobalS = {42, 3.14, 0};
18 ; int testOneFieldGlobalS() {
20 ; if (GlobalS.a != 42)
22 ; if (GlobalS.b == 3.14)
29 @GlobalS = internal constant %struct.S { i32 42, double 3.140000e+00, ptr null, i32 0 }, align 8
31 declare void @harmless_use(ptr nocapture readonly) nofree norecurse nosync nounwind readnone willreturn nocallback
34 ; CHECK: @[[GLOBALS:[a-zA-Z0-9_$"\\.-]+]] = internal constant [[STRUCT_S:%.*]] { i32 42, double 3.140000e+00, ptr null, i32 0 }, align 8
36 define i32 @testOneFieldGlobalS(i32 %cmpx) {
37 ; CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(none)
38 ; CHECK-LABEL: define {{[^@]+}}@testOneFieldGlobalS
39 ; CHECK-SAME: (i32 [[CMPX:%.*]]) #[[ATTR1:[0-9]+]] {
41 ; CHECK-NEXT: [[RMW:%.*]] = atomicrmw add ptr getelementptr inbounds ([[STRUCT_S:%.*]], ptr @GlobalS, i32 0, i32 3), i32 1 monotonic, align 4
42 ; CHECK-NEXT: [[CXI:%.*]] = cmpxchg ptr getelementptr inbounds ([[STRUCT_S]], ptr @GlobalS, i32 0, i32 3), i32 [[CMPX]], i32 7 acq_rel monotonic, align 4
43 ; CHECK-NEXT: br label [[IF_END:%.*]]
45 ; CHECK-NEXT: unreachable
47 ; CHECK-NEXT: br label [[IF_THEN2:%.*]]
49 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 0, 2
50 ; CHECK-NEXT: br label [[IF_END4:%.*]]
52 ; CHECK-NEXT: br label [[IF_END7:%.*]]
54 ; CHECK-NEXT: unreachable
56 ; CHECK-NEXT: ret i32 2
59 %i = load i32, ptr @GlobalS, align 8
60 call void @harmless_use(ptr @GlobalS)
61 %rmw = atomicrmw add ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 3), i32 1 monotonic, align 4
62 %cxi = cmpxchg ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 3), i32 %cmpx, i32 7 acq_rel monotonic
63 %cmp = icmp ne i32 %i, 42
64 br i1 %cmp, label %if.then, label %if.end
66 if.then: ; preds = %entry
67 %add = add nsw i32 0, 1
70 if.end: ; preds = %if.then, %entry
71 %r.0 = phi i32 [ %add, %if.then ], [ 0, %entry ]
72 %i1 = load double, ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 1), align 8
73 %cmp1 = fcmp oeq double %i1, 3.140000e+00
74 br i1 %cmp1, label %if.then2, label %if.end4
76 if.then2: ; preds = %if.end
77 %add3 = add nsw i32 %r.0, 2
80 if.end4: ; preds = %if.then2, %if.end
81 %r.1 = phi i32 [ %add3, %if.then2 ], [ %r.0, %if.end ]
82 %i2 = load ptr, ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 2), align 8
83 %tobool = icmp ne ptr %i2, null
84 br i1 %tobool, label %if.then5, label %if.end7
86 if.then5: ; preds = %if.end4
87 %add6 = add nsw i32 %r.1, 4
90 if.end7: ; preds = %if.then5, %if.end4
91 %r.2 = phi i32 [ %add6, %if.then5 ], [ %r.1, %if.end4 ]
95 define i32 @testOneFieldGlobalS_type_mismatch() {
96 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
97 ; CHECK-LABEL: define {{[^@]+}}@testOneFieldGlobalS_type_mismatch
98 ; CHECK-SAME: () #[[ATTR2:[0-9]+]] {
100 ; CHECK-NEXT: br label [[IF_THEN:%.*]]
102 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 0, 1
103 ; CHECK-NEXT: br label [[IF_END:%.*]]
105 ; CHECK-NEXT: br label [[IF_END4:%.*]]
107 ; CHECK-NEXT: unreachable
109 ; CHECK-NEXT: br label [[IF_END7:%.*]]
111 ; CHECK-NEXT: unreachable
113 ; CHECK-NEXT: ret i32 1
116 %i = load double, ptr @GlobalS, align 8
117 %ic = fptosi double %i to i32
118 %cmp = icmp ne i32 %ic, 42
119 br i1 %cmp, label %if.then, label %if.end
121 if.then: ; preds = %entry
122 %add = add nsw i32 0, 1
125 if.end: ; preds = %if.then, %entry
126 %r.0 = phi i32 [ %add, %if.then ], [ 0, %entry ]
127 %i1 = load i64, ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 1), align 8
128 %i1c = sitofp i64 %i1 to double
129 %cmp1 = fcmp oeq double %i1c, 3.140000e+00
130 br i1 %cmp1, label %if.then2, label %if.end4
132 if.then2: ; preds = %if.end
133 %add3 = add nsw i32 %r.0, 2
136 if.end4: ; preds = %if.then2, %if.end
137 %r.1 = phi i32 [ %add3, %if.then2 ], [ %r.0, %if.end ]
138 %i2 = load i64, ptr getelementptr inbounds (%struct.S, ptr @GlobalS, i32 0, i32 2), align 8
139 %i2c = inttoptr i64 %i2 to ptr
140 %tobool = icmp ne ptr %i2c, null
141 br i1 %tobool, label %if.then5, label %if.end7
143 if.then5: ; preds = %if.end4
144 %add6 = add nsw i32 %r.1, 4
147 if.end7: ; preds = %if.then5, %if.end4
148 %r.2 = phi i32 [ %add6, %if.then5 ], [ %r.1, %if.end4 ]
152 define i32 @testOneFieldGlobalS_byte_offset_wrong() {
153 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
154 ; CHECK-LABEL: define {{[^@]+}}@testOneFieldGlobalS_byte_offset_wrong
155 ; CHECK-SAME: () #[[ATTR2]] {
157 ; CHECK-NEXT: br label [[IF_THEN:%.*]]
159 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 0, 1
160 ; CHECK-NEXT: br label [[IF_END:%.*]]
162 ; CHECK-NEXT: [[I1:%.*]] = load double, ptr getelementptr (double, ptr @GlobalS, i32 3), align 8
163 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq double [[I1]], 3.140000e+00
164 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END4:%.*]]
166 ; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 1, 2
167 ; CHECK-NEXT: br label [[IF_END4]]
169 ; CHECK-NEXT: [[R_1:%.*]] = phi i32 [ [[ADD3]], [[IF_THEN2]] ], [ 1, [[IF_END]] ]
170 ; CHECK-NEXT: br label [[IF_END7:%.*]]
172 ; CHECK-NEXT: unreachable
174 ; CHECK-NEXT: ret i32 [[R_1]]
177 %i = load i32, ptr getelementptr (i32, ptr @GlobalS, i32 1), align 8
178 %cmp = icmp ne i32 %i, 42
179 br i1 %cmp, label %if.then, label %if.end
181 if.then: ; preds = %entry
182 %add = add nsw i32 0, 1
185 if.end: ; preds = %if.then, %entry
186 %r.0 = phi i32 [ %add, %if.then ], [ 0, %entry ]
187 %i1 = load double, ptr getelementptr (double, ptr @GlobalS, i32 3), align 8
188 %cmp1 = fcmp oeq double %i1, 3.140000e+00
189 br i1 %cmp1, label %if.then2, label %if.end4
191 if.then2: ; preds = %if.end
192 %add3 = add nsw i32 %r.0, 2
195 if.end4: ; preds = %if.then2, %if.end
196 %r.1 = phi i32 [ %add3, %if.then2 ], [ %r.0, %if.end ]
197 %i2 = load ptr, ptr getelementptr (ptr, ptr @GlobalS, i32 2), align 8
198 %tobool = icmp ne ptr %i2, null
199 br i1 %tobool, label %if.then5, label %if.end7
201 if.then5: ; preds = %if.end4
202 %add6 = add nsw i32 %r.1, 4
205 if.end7: ; preds = %if.then5, %if.end4
206 %r.2 = phi i32 [ %add6, %if.then5 ], [ %r.1, %if.end4 ]
210 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree norecurse nosync nounwind willreturn memory(none) }
211 ; CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nounwind willreturn memory(none) }
212 ; CHECK: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
214 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: