1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; Verify that the result of memchr calls with past-the-end pointers used
5 ; in equality expressions don't cause trouble and either are folded when
6 ; they might be valid or not when they're provably undefined.
8 declare ptr @memchr(ptr, i32, i64)
11 @a5 = constant [5 x i8] c"12345"
14 ; Fold memchr(a5 + 5, c, 1) == a5 + 5 to an arbitrary constrant.
15 ; The call is transformed to a5[5] == c by the memchr simplifier, with
16 ; a5[5] being indeterminate. The equality then is the folded with
17 ; an undefined/arbitrary result.
19 define i1 @call_memchr_ap5_c_1_eq_a(i32 %c, i64 %n) {
20 ; CHECK-LABEL: @call_memchr_ap5_c_1_eq_a(
21 ; CHECK-NEXT: ret i1 poison
23 %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 5
24 %qap5 = getelementptr [5 x i8], ptr @a5, i32 1, i32 0
25 %q = call ptr @memchr(ptr %pap5, i32 %c, i64 1)
26 %cmp = icmp eq ptr %q, %qap5
31 ; Fold memchr(a5 + 5, c, 5) == a5 + 5 to an arbitrary constant.
33 define i1 @call_memchr_ap5_c_5_eq_a(i32 %c, i64 %n) {
34 ; CHECK-LABEL: @call_memchr_ap5_c_5_eq_a(
35 ; CHECK-NEXT: ret i1 poison
37 %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 5
38 %qap5 = getelementptr [5 x i8], ptr @a5, i32 1, i32 0
39 %q = call ptr @memchr(ptr %pap5, i32 %c, i64 5)
40 %cmp = icmp eq ptr %q, %qap5
45 ; Fold memchr(a5 + 5, c, n) == a5 to false.
47 define i1 @fold_memchr_ap5_c_n_eq_a(i32 %c, i64 %n) {
48 ; CHECK-LABEL: @fold_memchr_ap5_c_n_eq_a(
49 ; CHECK-NEXT: ret i1 false
51 %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 5
52 %q = call ptr @memchr(ptr %pap5, i32 %c, i64 %n)
53 %cmp = icmp eq ptr %q, @a5
58 ; Fold memchr(a5 + 5, c, n) == null to true on the basis that n must
59 ; be zero in order for the call to be valid.
61 define i1 @fold_memchr_ap5_c_n_eqz(i32 %c, i64 %n) {
62 ; CHECK-LABEL: @fold_memchr_ap5_c_n_eqz(
63 ; CHECK-NEXT: ret i1 true
65 %p = getelementptr [5 x i8], ptr @a5, i32 0, i32 5
66 %q = call ptr @memchr(ptr %p, i32 %c, i64 %n)
67 %cmp = icmp eq ptr %q, null
72 ; Fold memchr(a5 + 5, '\0', n) == null to true on the basis that n must
73 ; be zero in order for the call to be valid.
75 define i1 @fold_memchr_a_nul_n_eqz(i64 %n) {
76 ; CHECK-LABEL: @fold_memchr_a_nul_n_eqz(
77 ; CHECK-NEXT: ret i1 true
79 %p = getelementptr [5 x i8], ptr @a5, i32 0, i32 5
80 %q = call ptr @memchr(ptr %p, i32 0, i64 %n)
81 %cmp = icmp eq ptr %q, null