1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Verify that calls to memcmp with arrays of elements larger than char
3 ; are folded correctly.
4 ; RUN: opt < %s -passes=instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=BE
5 ; RUN: opt < %s -passes=instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=LE
7 declare i32 @memcmp(ptr, ptr, i64)
9 ; BE representation: { 'a', 'b', 'c', ..., 'f', 'g', 'h' }
10 ; LE representation: { 'b', 'a', 'd', ..., 'e', 'h', 'g' }
11 @ia16a = constant [4 x i16] [i16 24930, i16 25444, i16 25958, i16 26472]
13 ; Same as the BE representation above except ending in "gg".
14 @i8a = constant [8 x i8] c"abcdefgg"
16 ; Fold memcmp(ia16a, i8a, N) for N in [0, 8].
18 define void @fold_memcmp_ia16a_i8a(ptr %pcmp) {
19 ; BE-LABEL: @fold_memcmp_ia16a_i8a(
20 ; BE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 4
21 ; BE-NEXT: [[PSTOR1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 4
22 ; BE-NEXT: store i32 0, ptr [[PSTOR1]], align 4
23 ; BE-NEXT: [[PSTOR2:%.*]] = getelementptr i8, ptr [[PCMP]], i64 8
24 ; BE-NEXT: store i32 0, ptr [[PSTOR2]], align 4
25 ; BE-NEXT: [[PSTOR3:%.*]] = getelementptr i8, ptr [[PCMP]], i64 12
26 ; BE-NEXT: store i32 0, ptr [[PSTOR3]], align 4
27 ; BE-NEXT: [[PSTOR4:%.*]] = getelementptr i8, ptr [[PCMP]], i64 16
28 ; BE-NEXT: store i32 0, ptr [[PSTOR4]], align 4
29 ; BE-NEXT: [[PSTOR5:%.*]] = getelementptr i8, ptr [[PCMP]], i64 20
30 ; BE-NEXT: store i32 0, ptr [[PSTOR5]], align 4
31 ; BE-NEXT: [[PSTOR6:%.*]] = getelementptr i8, ptr [[PCMP]], i64 24
32 ; BE-NEXT: store i32 0, ptr [[PSTOR6]], align 4
33 ; BE-NEXT: [[PSTOR7:%.*]] = getelementptr i8, ptr [[PCMP]], i64 28
34 ; BE-NEXT: store i32 0, ptr [[PSTOR7]], align 4
35 ; BE-NEXT: [[PSTOR8:%.*]] = getelementptr i8, ptr [[PCMP]], i64 32
36 ; BE-NEXT: store i32 1, ptr [[PSTOR8]], align 4
39 ; LE-LABEL: @fold_memcmp_ia16a_i8a(
40 ; LE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 4
41 ; LE-NEXT: [[PSTOR1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 4
42 ; LE-NEXT: store i32 1, ptr [[PSTOR1]], align 4
43 ; LE-NEXT: [[PSTOR2:%.*]] = getelementptr i8, ptr [[PCMP]], i64 8
44 ; LE-NEXT: store i32 1, ptr [[PSTOR2]], align 4
45 ; LE-NEXT: [[PSTOR3:%.*]] = getelementptr i8, ptr [[PCMP]], i64 12
46 ; LE-NEXT: store i32 1, ptr [[PSTOR3]], align 4
47 ; LE-NEXT: [[PSTOR4:%.*]] = getelementptr i8, ptr [[PCMP]], i64 16
48 ; LE-NEXT: store i32 1, ptr [[PSTOR4]], align 4
49 ; LE-NEXT: [[PSTOR5:%.*]] = getelementptr i8, ptr [[PCMP]], i64 20
50 ; LE-NEXT: store i32 1, ptr [[PSTOR5]], align 4
51 ; LE-NEXT: [[PSTOR6:%.*]] = getelementptr i8, ptr [[PCMP]], i64 24
52 ; LE-NEXT: store i32 1, ptr [[PSTOR6]], align 4
53 ; LE-NEXT: [[PSTOR7:%.*]] = getelementptr i8, ptr [[PCMP]], i64 28
54 ; LE-NEXT: store i32 1, ptr [[PSTOR7]], align 4
55 ; LE-NEXT: [[PSTOR8:%.*]] = getelementptr i8, ptr [[PCMP]], i64 32
56 ; LE-NEXT: store i32 1, ptr [[PSTOR8]], align 4
60 %cmp0 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 0)
61 store i32 %cmp0, ptr %pcmp
63 %cmp1 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 1)
64 %pstor1 = getelementptr i32, ptr %pcmp, i64 1
65 store i32 %cmp1, ptr %pstor1
67 %cmp2 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 2)
68 %pstor2 = getelementptr i32, ptr %pcmp, i64 2
69 store i32 %cmp2, ptr %pstor2
71 %cmp3 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 3)
72 %pstor3 = getelementptr i32, ptr %pcmp, i64 3
73 store i32 %cmp3, ptr %pstor3
75 %cmp4 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 4)
76 %pstor4 = getelementptr i32, ptr %pcmp, i64 4
77 store i32 %cmp4, ptr %pstor4
79 %cmp5 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 5)
80 %pstor5 = getelementptr i32, ptr %pcmp, i64 5
81 store i32 %cmp5, ptr %pstor5
83 %cmp6 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 6)
84 %pstor6 = getelementptr i32, ptr %pcmp, i64 6
85 store i32 %cmp6, ptr %pstor6
87 %cmp7 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 7)
88 %pstor7 = getelementptr i32, ptr %pcmp, i64 7
89 store i32 %cmp7, ptr %pstor7
91 %cmp8 = call i32 @memcmp(ptr @ia16a, ptr @i8a, i64 8)
92 %pstor8 = getelementptr i32, ptr %pcmp, i64 8
93 store i32 %cmp8, ptr %pstor8
99 ; Fold memcmp(ia16a + 1, i8a + 2, N) for N in [0, 6].
101 define void @fold_memcmp_ia16a_p1_i8a_p1(ptr %pcmp) {
102 ; BE-LABEL: @fold_memcmp_ia16a_p1_i8a_p1(
103 ; BE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 4
104 ; BE-NEXT: [[PSTOR1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 4
105 ; BE-NEXT: store i32 1, ptr [[PSTOR1]], align 4
106 ; BE-NEXT: [[PSTOR2:%.*]] = getelementptr i8, ptr [[PCMP]], i64 8
107 ; BE-NEXT: store i32 1, ptr [[PSTOR2]], align 4
108 ; BE-NEXT: [[PSTOR3:%.*]] = getelementptr i8, ptr [[PCMP]], i64 12
109 ; BE-NEXT: store i32 1, ptr [[PSTOR3]], align 4
110 ; BE-NEXT: [[PSTOR4:%.*]] = getelementptr i8, ptr [[PCMP]], i64 16
111 ; BE-NEXT: store i32 1, ptr [[PSTOR4]], align 4
112 ; BE-NEXT: [[PSTOR5:%.*]] = getelementptr i8, ptr [[PCMP]], i64 20
113 ; BE-NEXT: store i32 1, ptr [[PSTOR5]], align 4
114 ; BE-NEXT: [[PSTOR6:%.*]] = getelementptr i8, ptr [[PCMP]], i64 24
115 ; BE-NEXT: store i32 1, ptr [[PSTOR6]], align 4
118 ; LE-LABEL: @fold_memcmp_ia16a_p1_i8a_p1(
119 ; LE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 4
120 ; LE-NEXT: [[PSTOR1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 4
121 ; LE-NEXT: store i32 1, ptr [[PSTOR1]], align 4
122 ; LE-NEXT: [[PSTOR2:%.*]] = getelementptr i8, ptr [[PCMP]], i64 8
123 ; LE-NEXT: store i32 1, ptr [[PSTOR2]], align 4
124 ; LE-NEXT: [[PSTOR3:%.*]] = getelementptr i8, ptr [[PCMP]], i64 12
125 ; LE-NEXT: store i32 1, ptr [[PSTOR3]], align 4
126 ; LE-NEXT: [[PSTOR4:%.*]] = getelementptr i8, ptr [[PCMP]], i64 16
127 ; LE-NEXT: store i32 1, ptr [[PSTOR4]], align 4
128 ; LE-NEXT: [[PSTOR5:%.*]] = getelementptr i8, ptr [[PCMP]], i64 20
129 ; LE-NEXT: store i32 1, ptr [[PSTOR5]], align 4
130 ; LE-NEXT: [[PSTOR6:%.*]] = getelementptr i8, ptr [[PCMP]], i64 24
131 ; LE-NEXT: store i32 1, ptr [[PSTOR6]], align 4
134 %p0 = getelementptr [4 x i16], ptr @ia16a, i64 0, i64 1
135 %q = getelementptr [8 x i8], ptr @i8a, i64 0, i64 1
137 %cmp0 = call i32 @memcmp(ptr %p0, ptr %q, i64 0)
138 store i32 %cmp0, ptr %pcmp
140 %cmp1 = call i32 @memcmp(ptr %p0, ptr %q, i64 1)
141 %pstor1 = getelementptr i32, ptr %pcmp, i64 1
142 store i32 %cmp1, ptr %pstor1
144 %cmp2 = call i32 @memcmp(ptr %p0, ptr %q, i64 2)
145 %pstor2 = getelementptr i32, ptr %pcmp, i64 2
146 store i32 %cmp2, ptr %pstor2
148 %cmp3 = call i32 @memcmp(ptr %p0, ptr %q, i64 3)
149 %pstor3 = getelementptr i32, ptr %pcmp, i64 3
150 store i32 %cmp3, ptr %pstor3
152 %cmp4 = call i32 @memcmp(ptr %p0, ptr %q, i64 4)
153 %pstor4 = getelementptr i32, ptr %pcmp, i64 4
154 store i32 %cmp4, ptr %pstor4
156 %cmp5 = call i32 @memcmp(ptr %p0, ptr %q, i64 5)
157 %pstor5 = getelementptr i32, ptr %pcmp, i64 5
158 store i32 %cmp5, ptr %pstor5
160 %cmp6 = call i32 @memcmp(ptr %p0, ptr %q, i64 6)
161 %pstor6 = getelementptr i32, ptr %pcmp, i64 6
162 store i32 %cmp6, ptr %pstor6