@@ -130,3 +130,63 @@ entry:
130
130
%res = call i32 @memcmp (i8* nonnull %foo , i8* nonnull %stack.ptr , i64 %n )
131
131
ret i32 %res
132
132
}
133
+
134
+ declare i32 @bcmp (i8* , i8* , i64 )
135
+
136
+ define i1 @test_bcmp_const_size (i8* noalias %foo ) {
137
+ ; CHECK-LABEL: @test_bcmp_const_size(
138
+ ; CHECK-NEXT: entry:
139
+ ; CHECK-NEXT: [[STACK:%.*]] = alloca [10 x i8], align 1
140
+ ; CHECK-NEXT: [[STACK_PTR:%.*]] = bitcast [10 x i8]* [[STACK]] to i8*
141
+ ; CHECK-NEXT: store i8 49, i8* [[STACK_PTR]], align 1
142
+ ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 1
143
+ ; CHECK-NEXT: store i8 50, i8* [[GEP_1]], align 1
144
+ ; CHECK-NEXT: [[CALL:%.*]] = call i32 @bcmp(i8* nonnull dereferenceable(2) [[FOO:%.*]], i8* nonnull dereferenceable(2) [[STACK_PTR]], i64 2)
145
+ ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CALL]], 0
146
+ ; CHECK-NEXT: ret i1 [[RES]]
147
+ ;
148
+ entry:
149
+ %stack = alloca [10 x i8 ]
150
+ %stack.ptr = bitcast [10 x i8 ]* %stack to i8*
151
+ store i8 49 , i8* %stack.ptr , align 1
152
+ %gep.1 = getelementptr i8 , i8* %stack.ptr , i64 1
153
+ store i8 50 , i8* %gep.1 , align 1
154
+ %gep.2 = getelementptr i8 , i8* %stack.ptr , i64 2
155
+ store i8 51 , i8* %gep.2 , align 1
156
+ %gep.3 = getelementptr i8 , i8* %stack.ptr , i64 3
157
+ store i8 52 , i8* %gep.3 , align 1
158
+ %call = call i32 @bcmp (i8* nonnull dereferenceable (2 ) %foo , i8* nonnull dereferenceable (2 ) %stack.ptr , i64 2 )
159
+ %res = icmp eq i32 %call , 0
160
+ ret i1 %res
161
+ }
162
+
163
+ define i1 @test_bcmp_variable_size (i8* noalias %foo , i64 %n ) {
164
+ ; CHECK-LABEL: @test_bcmp_variable_size(
165
+ ; CHECK-NEXT: entry:
166
+ ; CHECK-NEXT: [[STACK:%.*]] = alloca [10 x i8], align 1
167
+ ; CHECK-NEXT: [[STACK_PTR:%.*]] = bitcast [10 x i8]* [[STACK]] to i8*
168
+ ; CHECK-NEXT: store i8 49, i8* [[STACK_PTR]], align 1
169
+ ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 1
170
+ ; CHECK-NEXT: store i8 50, i8* [[GEP_1]], align 1
171
+ ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 2
172
+ ; CHECK-NEXT: store i8 51, i8* [[GEP_2]], align 1
173
+ ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 3
174
+ ; CHECK-NEXT: store i8 52, i8* [[GEP_3]], align 1
175
+ ; CHECK-NEXT: [[CALL:%.*]] = call i32 @bcmp(i8* nonnull [[FOO:%.*]], i8* nonnull [[STACK_PTR]], i64 [[N:%.*]])
176
+ ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CALL]], 0
177
+ ; CHECK-NEXT: ret i1 [[RES]]
178
+ ;
179
+ entry:
180
+ %stack = alloca [10 x i8 ]
181
+ %stack.ptr = bitcast [10 x i8 ]* %stack to i8*
182
+ store i8 49 , i8* %stack.ptr , align 1
183
+ %gep.1 = getelementptr i8 , i8* %stack.ptr , i64 1
184
+ store i8 50 , i8* %gep.1 , align 1
185
+ %gep.2 = getelementptr i8 , i8* %stack.ptr , i64 2
186
+ store i8 51 , i8* %gep.2 , align 1
187
+ %gep.3 = getelementptr i8 , i8* %stack.ptr , i64 3
188
+ store i8 52 , i8* %gep.3 , align 1
189
+ %call = call i32 @bcmp (i8* nonnull %foo , i8* nonnull %stack.ptr , i64 %n )
190
+ %res = icmp eq i32 %call , 0
191
+ ret i1 %res
192
+ }
0 commit comments