xref: /llvm-project/llvm/test/Transforms/InstCombine/memchr-8.ll (revision 10f315dc9c96ec2413881ab55a285e35d80def88)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3;
4; Verify that a constant with size in excess of 32-bit SIZE_MAX doesn't
5; cause trouble.  This test exercises an internal limit set arbitrarily
6; at 64K for the largest supported zeroinitiazer. If the limit changes
7; the test might need to be adjusted.
8
9declare ptr @memrchr(ptr, i32, i64)
10
11@a = constant <{ i8, [4294967295 x i8] }> <{ i8 1, [4294967295 x i8] zeroinitializer }>
12
13; Verify reading an initializer INT32_MAX + 1 bytes large (starting at
14; offset 2147483647 into a which is UINT32_MAX bytes in size).
15
16define ptr @call_a_pi32max_p1() {
17; CHECK-LABEL: @call_a_pi32max_p1(
18; CHECK-NEXT:    [[CHR:%.*]] = tail call ptr @memrchr(ptr noundef nonnull dereferenceable(2147483647) getelementptr inbounds nuw (i8, ptr @a, i64 2147483648), i32 0, i64 2147483647)
19; CHECK-NEXT:    ret ptr [[CHR]]
20;
21  %ptr = getelementptr <{ i8, [4294967295 x i8] }>, ptr @a, i32 0, i32 1, i32 2147483647
22  %chr = tail call ptr @memrchr(ptr %ptr, i32 0, i64 2147483647)
23  ret ptr %chr
24}
25
26; Verify reading an initializer INT32_MAX bytes large (starting at offset
27; 2147483648 into a which is UINT32_MAX bytes in size).
28
29define ptr @call_a_pi32max() {
30; CHECK-LABEL: @call_a_pi32max(
31; CHECK-NEXT:    [[CHR:%.*]] = tail call ptr @memrchr(ptr noundef nonnull dereferenceable(2147483647) getelementptr inbounds nuw (i8, ptr @a, i64 2147483649), i32 0, i64 2147483647)
32; CHECK-NEXT:    ret ptr [[CHR]]
33;
34  %ptr = getelementptr <{ i8, [4294967295 x i8] }>, ptr @a, i32 0, i32 1, i64 2147483648
35  %chr = tail call ptr @memrchr(ptr %ptr, i32 0, i64 2147483647)
36  ret ptr %chr
37}
38
39
40; Verify reading an initializer UINT32_MAX bytes large (starting at offset
41; 1 into a).
42
43define ptr @call_a_pui32max() {
44; CHECK-LABEL: @call_a_pui32max(
45; CHECK-NEXT:    [[CHR:%.*]] = tail call ptr @memrchr(ptr noundef nonnull dereferenceable(4294967295) getelementptr inbounds nuw (i8, ptr @a, i64 1), i32 0, i64 4294967295)
46; CHECK-NEXT:    ret ptr [[CHR]]
47;
48  %ptr = getelementptr <{ i8, [4294967295 x i8] }>, ptr @a, i32 0, i32 1, i32 0
49  %chr = tail call ptr @memrchr(ptr %ptr, i32 0, i64 4294967295)
50  ret ptr %chr
51}
52
53; Verify reading an initializer UINT32_MAX + 1 bytes large (all of a).
54
55define ptr @call_a_puimax_p1() {
56; CHECK-LABEL: @call_a_puimax_p1(
57; CHECK-NEXT:    [[CHR:%.*]] = tail call ptr @memrchr(ptr noundef nonnull dereferenceable(4294967296) @a, i32 0, i64 4294967296)
58; CHECK-NEXT:    ret ptr [[CHR]]
59;
60  %ptr = getelementptr <{ i8, [4294967295 x i8] }>, ptr @a, i32 0, i32 0
61  %chr = tail call ptr @memrchr(ptr %ptr, i32 0, i64 4294967296)
62  ret ptr %chr
63}
64