brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 686e1d5 Raw
84 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3;4; Verify that the result of memrchr calls with past-the-end pointers used5; in equality expressions don't cause trouble and either are folded when6; they might be valid or not when they're provably undefined.7 8declare ptr @memrchr(ptr, i32, i64)9 10 11@a5 = constant [5 x i8] c"12345"12 13 14; Fold memrchr(a5 + 5, c, 1) == a5 + 5 to an arbitrary constant.15; The call is transformed to a5[5] == c by the memrchr simplifier, with16; a5[5] being indeterminate.  The equality then is the folded with17; an undefined/arbitrary result.18 19define i1 @call_memrchr_ap5_c_1_eq_a(i32 %c, i64 %n) {20; CHECK-LABEL: @call_memrchr_ap5_c_1_eq_a(21; CHECK-NEXT:    ret i1 poison22;23  %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 524  %qap5 = getelementptr [5 x i8], ptr @a5, i32 1, i32 025  %q = call ptr @memrchr(ptr %pap5, i32 %c, i64 1)26  %cmp = icmp eq ptr %q, %qap527  ret i1 %cmp28}29 30 31; Fold memrchr(a5 + 5, c, 5) == a5 + 5 to an arbitrary constant.32 33define i1 @call_memrchr_ap5_c_5_eq_a(i32 %c, i64 %n) {34; CHECK-LABEL: @call_memrchr_ap5_c_5_eq_a(35; CHECK-NEXT:    ret i1 false36;37  %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 538  %qap5 = getelementptr [5 x i8], ptr @a5, i32 1, i32 039  %q = call ptr @memrchr(ptr %pap5, i32 %c, i64 5)40  %cmp = icmp eq ptr %q, %qap541  ret i1 %cmp42}43 44 45; Fold memrchr(a5 + 5, c, n) == a5 to false.46 47define i1 @fold_memrchr_ap5_c_n_eq_a(i32 %c, i64 %n) {48; CHECK-LABEL: @fold_memrchr_ap5_c_n_eq_a(49; CHECK-NEXT:    ret i1 false50;51  %pap5 = getelementptr [5 x i8], ptr @a5, i32 0, i32 552  %q = call ptr @memrchr(ptr %pap5, i32 %c, i64 %n)53  %cmp = icmp eq ptr %q, @a554  ret i1 %cmp55}56 57 58; Fold memrchr(a5 + 5, c, n) == null to true on the basis that n must59; be zero in order for the call to be valid.60 61define i1 @fold_memrchr_ap5_c_n_eqz(i32 %c, i64 %n) {62; CHECK-LABEL: @fold_memrchr_ap5_c_n_eqz(63; CHECK-NEXT:    ret i1 true64;65  %p = getelementptr [5 x i8], ptr @a5, i32 0, i32 566  %q = call ptr @memrchr(ptr %p, i32 %c, i64 %n)67  %cmp = icmp eq ptr %q, null68  ret i1 %cmp69}70 71 72; Fold memrchr(a5 + 5, '\0', n) == null to true again on the basis that73; n must be zero in order for the call to be valid.74 75define i1 @fold_memrchr_a_nul_n_eqz(i64 %n) {76; CHECK-LABEL: @fold_memrchr_a_nul_n_eqz(77; CHECK-NEXT:    ret i1 true78;79  %p = getelementptr [5 x i8], ptr @a5, i32 0, i32 580  %q = call ptr @memrchr(ptr %p, i32 0, i64 %n)81  %cmp = icmp eq ptr %q, null82  ret i1 %cmp83}84