File: strrchr-3.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (62 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Verify the strrchr("", c) to (unsigned char)c ? "" : 0 transformetion.
;
; RUN: opt < %s -passes=instcombine -S | FileCheck %s

@s10 = constant [11 x i8] c"0123456789\00"

declare ptr @strrchr(ptr, i32)

; Fold strrchr(s + 10, c) to (unsigned char)c ? 0 : s + 10.

define ptr @fold_strrchr_sp10_x(i32 %c) {
; CHECK-LABEL: @fold_strrchr_sp10_x(
; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[C:%.*]] to i8
; CHECK-NEXT:    [[MEMRCHR_CHAR0CMP:%.*]] = icmp eq i8 [[TMP1]], 0
; CHECK-NEXT:    [[MEMRCHR_SEL:%.*]] = select i1 [[MEMRCHR_CHAR0CMP]], ptr getelementptr inbounds (i8, ptr @s10, i64 10), ptr null
; CHECK-NEXT:    ret ptr [[MEMRCHR_SEL]]
;
  %psp10 = getelementptr [11 x i8], ptr @s10, i32 0, i32 10
  %pc = call ptr @strrchr(ptr %psp10, i32 %c)
  ret ptr %pc
}


; Transform strrchr(s + 9, c) to [the equivalent of] memrchr(s + 9, c, 2).

define ptr @call_strrchr_sp9_x(i32 %c) {
; CHECK-LABEL: @call_strrchr_sp9_x(
; CHECK-NEXT:    [[MEMRCHR:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(2) getelementptr inbounds (i8, ptr @s10, i64 9), i32 [[C:%.*]], i64 2)
; CHECK-NEXT:    ret ptr [[MEMRCHR]]
;
  %psp9 = getelementptr [11 x i8], ptr @s10, i32 0, i32 9
  %pc = call ptr @strrchr(ptr %psp9, i32 %c)
  ret ptr %pc
}


; Do not transform strrchr(s + 2, c) (for short strings this could be
; folded into a chain of OR expressions ala D128011).

define ptr @call_strrchr_sp2_x(i32 %c) {
; CHECK-LABEL: @call_strrchr_sp2_x(
; CHECK-NEXT:    [[MEMRCHR:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(9) getelementptr inbounds (i8, ptr @s10, i64 2), i32 [[C:%.*]], i64 9)
; CHECK-NEXT:    ret ptr [[MEMRCHR]]
;
  %psp2 = getelementptr [11 x i8], ptr @s10, i32 0, i32 2
  %pc = call ptr @strrchr(ptr %psp2, i32 %c)
  ret ptr %pc
}


; Do not transform strrchr(s + 1, c).

define ptr @call_strrchr_sp1_x(i32 %c) {
; CHECK-LABEL: @call_strrchr_sp1_x(
; CHECK-NEXT:    [[MEMRCHR:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(10) getelementptr inbounds (i8, ptr @s10, i64 1), i32 [[C:%.*]], i64 10)
; CHECK-NEXT:    ret ptr [[MEMRCHR]]
;
  %psp1 = getelementptr [11 x i8], ptr @s10, i32 0, i32 1
  %pc = call ptr @strrchr(ptr %psp1, i32 %c)
  ret ptr %pc
}