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 memrchr calls used in equality expressions
5 ; with the first argument aren't folded like the corresponding calls
7 ; Folding of equality expressions with the first argument plus the bound
8 ; -1, i.e., memrchr(S, C, N) == N && S[N - 1] == C is not implemented.
10 declare ptr @memrchr(ptr, i32, i64)
13 @a5 = constant [5 x i8] c"12345";
15 ; Do not fold memrchr(a5, c, 9) == a5. The corresponding call to memchr
16 ; is folded so this test verifies that the memrchr folder doesn't make
17 ; the wrong assumption. The bound of 9 tries to avoid having to adjust
18 ; the test if the call is folded into a series of ORs as in D128011.
20 define i1 @call_memrchr_a_c_9_eq_a(i32 %c) {
21 ; CHECK-LABEL: @call_memrchr_a_c_9_eq_a(
22 ; CHECK-NEXT: [[Q:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(9) @a5, i32 [[C:%.*]], i64 9)
23 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Q]], @a5
24 ; CHECK-NEXT: ret i1 [[CMP]]
26 %q = call ptr @memrchr(ptr @a5, i32 %c, i64 9)
27 %cmp = icmp eq ptr %q, @a5
32 ; Do not fold memrchr(a5, c, n).
34 define i1 @call_memrchr_a_c_n_eq_a(i32 %c, i64 %n) {
35 ; CHECK-LABEL: @call_memrchr_a_c_n_eq_a(
36 ; CHECK-NEXT: [[Q:%.*]] = call ptr @memrchr(ptr nonnull @a5, i32 [[C:%.*]], i64 [[N:%.*]])
37 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[Q]], @a5
38 ; CHECK-NEXT: ret i1 [[CMP]]
40 %q = call ptr @memrchr(ptr @a5, i32 %c, i64 %n)
41 %cmp = icmp eq ptr %q, @a5
46 ; Do not fold memrchr(s, c, 17).
48 define i1 @call_memrchr_s_c_17_eq_s(ptr %s, i32 %c) {
49 ; CHECK-LABEL: @call_memrchr_s_c_17_eq_s(
50 ; CHECK-NEXT: [[P:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(17) [[S:%.*]], i32 [[C:%.*]], i64 17)
51 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[S]]
52 ; CHECK-NEXT: ret i1 [[CMP]]
54 %p = call ptr @memrchr(ptr %s, i32 %c, i64 17)
55 %cmp = icmp eq ptr %p, %s
60 ; Do not fold memrchr(s, c, 9).
62 define i1 @call_memrchr_s_c_9_neq_s(ptr %s, i32 %c) {
63 ; CHECK-LABEL: @call_memrchr_s_c_9_neq_s(
64 ; CHECK-NEXT: [[P:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(7) [[S:%.*]], i32 [[C:%.*]], i64 7)
65 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P]], [[S]]
66 ; CHECK-NEXT: ret i1 [[CMP]]
68 %p = call ptr @memrchr(ptr %s, i32 %c, i64 7)
69 %cmp = icmp ne ptr %p, %s
74 ; Do not fold memrchr(s, c, n).
76 define i1 @fold_memrchr_s_c_n_eq_s(ptr %s, i32 %c, i64 %n) {
77 ; CHECK-LABEL: @fold_memrchr_s_c_n_eq_s(
78 ; CHECK-NEXT: [[P:%.*]] = call ptr @memrchr(ptr [[S:%.*]], i32 [[C:%.*]], i64 [[N:%.*]])
79 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[S]]
80 ; CHECK-NEXT: ret i1 [[CMP]]
82 %p = call ptr @memrchr(ptr %s, i32 %c, i64 %n)
83 %cmp = icmp eq ptr %p, %s