File: memcmp-6.ll

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (106 lines) | stat: -rw-r--r-- 4,148 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
;
; Exercise folding of memcmp calls with constant arrays including both
; negative and positive characters and both constant and nonconstant sizes.

declare i32 @memcmp(i8*, i8*, i64)

@a = constant [7 x i8] c"abcdef\7f"
@b = constant [7 x i8] c"abcdef\80"


; Exercise memcmp(A + C, B + C, 2) folding of small arrays that differ in
; a character with the opposite sign and a constant size.

define void @fold_memcmp_cst_cst(i32* %pcmp) {
; CHECK-LABEL: @fold_memcmp_cst_cst(
; CHECK-NEXT:    store i32 -1, i32* [[PCMP:%.*]], align 4
; CHECK-NEXT:    [[SB5_A5:%.*]] = getelementptr i32, i32* [[PCMP]], i64 1
; CHECK-NEXT:    store i32 1, i32* [[SB5_A5]], align 4
; CHECK-NEXT:    [[SA6_B6:%.*]] = getelementptr i32, i32* [[PCMP]], i64 2
; CHECK-NEXT:    store i32 -1, i32* [[SA6_B6]], align 4
; CHECK-NEXT:    [[SB6_A6:%.*]] = getelementptr i32, i32* [[PCMP]], i64 3
; CHECK-NEXT:    store i32 1, i32* [[SB6_A6]], align 4
; CHECK-NEXT:    ret void
;
  %p5 = getelementptr [7 x i8], [7 x i8]* @a, i64 0, i64 5
  %p6 = getelementptr [7 x i8], [7 x i8]* @a, i64 0, i64 6

  %q5 = getelementptr [7 x i8], [7 x i8]* @b, i64 0, i64 5
  %q6 = getelementptr [7 x i8], [7 x i8]* @b, i64 0, i64 6

  ; Fold memcmp(a + 5, b + 5, 2) to -1.
  %ca5_b5 = call i32 @memcmp(i8* %p5, i8* %q5, i64 2)
  %sa5_b5 = getelementptr i32, i32* %pcmp, i64 0
  store i32 %ca5_b5, i32* %sa5_b5

  ; Fold memcmp(b + 5, a + 5, 2) to +1.
  %cb5_a5 = call i32 @memcmp(i8* %q5, i8* %p5, i64 2)
  %sb5_a5 = getelementptr i32, i32* %pcmp, i64 1
  store i32 %cb5_a5, i32* %sb5_a5

  ; Fold memcmp(a + 6, b + 6, 1) to -1.
  %ca6_b6 = call i32 @memcmp(i8* %p6, i8* %q6, i64 1)
  %sa6_b6 = getelementptr i32, i32* %pcmp, i64 2
  store i32 %ca6_b6, i32* %sa6_b6

  ; Fold memcmp(b + 6, a + 6, 1) to  +1.
  %cb6_a6 = call i32 @memcmp(i8* %q6, i8* %p6, i64 1)
  %sb6_a6 = getelementptr i32, i32* %pcmp, i64 3
  store i32 %cb6_a6, i32* %sb6_a6

  ret void
}


; Exercise memcmp(A, B, N) folding of arrays that differ in a character
; with the opposite sign and a variable size

define void @fold_memcmp_cst_var(i32* %pcmp, i64 %n) {
; CHECK-LABEL: @fold_memcmp_cst_var(
; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i64 [[N:%.*]], 6
; CHECK-NEXT:    [[TMP2:%.*]] = sext i1 [[TMP1]] to i32
; CHECK-NEXT:    store i32 [[TMP2]], i32* [[PCMP:%.*]], align 4
; CHECK-NEXT:    [[TMP3:%.*]] = icmp ugt i64 [[N]], 6
; CHECK-NEXT:    [[TMP4:%.*]] = zext i1 [[TMP3]] to i32
; CHECK-NEXT:    [[SB0_A0:%.*]] = getelementptr i32, i32* [[PCMP]], i64 1
; CHECK-NEXT:    store i32 [[TMP4]], i32* [[SB0_A0]], align 4
; CHECK-NEXT:    [[TMP5:%.*]] = icmp ne i64 [[N]], 0
; CHECK-NEXT:    [[TMP6:%.*]] = sext i1 [[TMP5]] to i32
; CHECK-NEXT:    [[SA6_B6:%.*]] = getelementptr i32, i32* [[PCMP]], i64 2
; CHECK-NEXT:    store i32 [[TMP6]], i32* [[SA6_B6]], align 4
; CHECK-NEXT:    [[TMP7:%.*]] = icmp ne i64 [[N]], 0
; CHECK-NEXT:    [[TMP8:%.*]] = zext i1 [[TMP7]] to i32
; CHECK-NEXT:    [[SB6_A6:%.*]] = getelementptr i32, i32* [[PCMP]], i64 3
; CHECK-NEXT:    store i32 [[TMP8]], i32* [[SB6_A6]], align 4
; CHECK-NEXT:    ret void
;
  %p0 = getelementptr [7 x i8], [7 x i8]* @a, i64 0, i64 0
  %p6 = getelementptr [7 x i8], [7 x i8]* @a, i64 0, i64 6

  %q0 = getelementptr [7 x i8], [7 x i8]* @b, i64 0, i64 0
  %q6 = getelementptr [7 x i8], [7 x i8]* @b, i64 0, i64 6

  ; Fold memcmp(a, b, n) to -1.
  %ca0_b0 = call i32 @memcmp(i8* %p0, i8* %q0, i64 %n)
  %sa0_b0 = getelementptr i32, i32* %pcmp, i64 0
  store i32 %ca0_b0, i32* %sa0_b0

  ; Fold memcmp(b, a, n) to +1.
  %cb0_a0 = call i32 @memcmp(i8* %q0, i8* %p0, i64 %n)
  %sb0_a0 = getelementptr i32, i32* %pcmp, i64 1
  store i32 %cb0_a0, i32* %sb0_a0

  ; Fold memcmp(a + 6, b + 6, n) to -1.
  %ca6_b6 = call i32 @memcmp(i8* %p6, i8* %q6, i64 %n)
  %sa6_b6 = getelementptr i32, i32* %pcmp, i64 2
  store i32 %ca6_b6, i32* %sa6_b6

  ; Fold memcmp(b + 6, a + 6, n) to +1.
  %cb6_a6 = call i32 @memcmp(i8* %q6, i8* %p6, i64 %n)
  %sb6_a6 = getelementptr i32, i32* %pcmp, i64 3
  store i32 %cb6_a6, i32* %sb6_a6

  ret void
}