1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; Verify that an excessive size to memchr() isn't truncated to an in-bounds
5 ; value that results in the call being incorrectly folded (as might happen
6 ; when LLVM is compiled in ILP32 mode).
8 declare ptr @memchr(ptr, i32, i64)
10 @ax = external global [0 x i8]
11 @a12345 = constant [5 x i8] c"\01\02\03\04\05"
14 ; Do not fold memchr(ax, 1, UINT_MAX + (size_t)1) to null. Only the first
15 ; byte in ax must be dereferenceable.
17 define ptr @call_memchr_ax_2_uimax_p1() {
18 ; CHECK-LABEL: @call_memchr_ax_2_uimax_p1(
19 ; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
20 ; CHECK-NEXT: ret ptr [[RES]]
23 %res = call ptr @memchr(ptr @ax, i32 1, i64 4294967296)
28 ; Do not fold memchr(ax, 1, UINT_MAX + (size_t)2) to *ax == 1 ? ax : null.
29 ; As above, only the first byte in ax must be dereferenceable.
31 define ptr @call_memchr_ax_2_uimax_p2() {
32 ; CHECK-LABEL: @call_memchr_ax_2_uimax_p2(
33 ; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
34 ; CHECK-NEXT: ret ptr [[RES]]
37 %res = call ptr @memchr(ptr @ax, i32 1, i64 4294967296)
42 ; Fold memchr(a12345, 3, UINT_MAX + (size_t)2) to a12345 + 2 (and not to
45 define ptr @fold_memchr_a12345_3_uimax_p2() {
46 ; CHECK-LABEL: @fold_memchr_a12345_3_uimax_p2(
47 ; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @a12345, i64 2)
50 %res = call ptr @memchr(ptr @a12345, i32 3, i64 4294967297)
55 ; Do not fold memchr(a12345, c, UINT_MAX + (size_t)2).
57 define ptr @fold_memchr_a12345_c_uimax_p2(i32 %0) {
58 ; CHECK-LABEL: @fold_memchr_a12345_c_uimax_p2(
59 ; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a12345, i32 [[TMP0:%.*]], i64 4294967297)
60 ; CHECK-NEXT: ret ptr [[RES]]
63 %res = call ptr @memchr(ptr @a12345, i32 %0, i64 4294967297)