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 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. 7 8declare ptr @memchr(ptr, i32, i64) 9 10 11@a5 = constant [5 x i8] c"12345" 12 13 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. 18 19define 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 22; 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 27 ret i1 %cmp 28} 29 30 31; Fold memchr(a5 + 5, c, 5) == a5 + 5 to an arbitrary constant. 32 33define 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 36; 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 41 ret i1 %cmp 42} 43 44 45; Fold memchr(a5 + 5, c, n) == a5 to false. 46 47define 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 50; 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 54 ret i1 %cmp 55} 56 57 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. 60 61define 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 64; 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 68 ret i1 %cmp 69} 70 71 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. 74 75define i1 @fold_memchr_a_nul_n_eqz(i64 %n) { 76; CHECK-LABEL: @fold_memchr_a_nul_n_eqz( 77; CHECK-NEXT: ret i1 true 78; 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 82 ret i1 %cmp 83} 84