1 ; RUN: llc -o - -mtriple=powerpc64le-unknown-gnu-linux -stop-after codegenprepare %s | FileCheck %s
2 ; RUN: llc -o - -mtriple=powerpc64-unknown-gnu-linux -stop-after codegenprepare %s | FileCheck %s --check-prefix=CHECK-BE
4 define signext i32 @test1(i32* nocapture readonly %buffer1, i32* nocapture readonly %buffer2) {
7 ; CHECK: [[LOAD1:%[0-9]+]] = load i64, i64*
8 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64*
9 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD1]])
10 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD2]])
11 ; CHECK-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[BSWAP1]], [[BSWAP2]]
12 ; CHECK-NEXT: br i1 [[ICMP]], label %loadbb1, label %res_block
14 ; CHECK-LABEL: res_block:{{.*}}
15 ; CHECK: [[ICMP2:%[0-9]+]] = icmp ult i64
16 ; CHECK-NEXT: [[SELECT:%[0-9]+]] = select i1 [[ICMP2]], i32 -1, i32 1
17 ; CHECK-NEXT: br label %endblock
19 ; CHECK-LABEL: loadbb1:{{.*}}
20 ; CHECK: [[BCC1:%[0-9]+]] = bitcast i32* {{.*}} to i8*
21 ; CHECK-NEXT: [[BCC2:%[0-9]+]] = bitcast i32* {{.*}} to i8*
22 ; CHECK-NEXT: [[GEP1:%[0-9]+]] = getelementptr i8, i8* [[BCC2]], i8 8
23 ; CHECK-NEXT: [[BCL1:%[0-9]+]] = bitcast i8* [[GEP1]] to i64*
24 ; CHECK-NEXT: [[GEP2:%[0-9]+]] = getelementptr i8, i8* [[BCC1]], i8 8
25 ; CHECK-NEXT: [[BCL2:%[0-9]+]] = bitcast i8* [[GEP2]] to i64*
26 ; CHECK-NEXT: [[LOAD1:%[0-9]+]] = load i64, i64* [[BCL1]]
27 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64* [[BCL2]]
28 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD1]])
29 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD2]])
30 ; CHECK-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[BSWAP1]], [[BSWAP2]]
31 ; CHECK-NEXT: br i1 [[ICMP]], label %endblock, label %res_block
33 ; CHECK-BE-LABEL: @test1(
34 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i64, i64*
35 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64*
36 ; CHECK-BE-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[LOAD1]], [[LOAD2]]
37 ; CHECK-BE-NEXT: br i1 [[ICMP]], label %loadbb1, label %res_block
39 ; CHECK-BE-LABEL: res_block:{{.*}}
40 ; CHECK-BE: [[ICMP2:%[0-9]+]] = icmp ult i64
41 ; CHECK-BE-NEXT: [[SELECT:%[0-9]+]] = select i1 [[ICMP2]], i32 -1, i32 1
42 ; CHECK-BE-NEXT: br label %endblock
44 ; CHECK-BE-LABEL: loadbb1:{{.*}}
45 ; CHECK-BE: [[BCC1:%[0-9]+]] = bitcast i32* {{.*}} to i8*
46 ; CHECK-BE-NEXT: [[BCC2:%[0-9]+]] = bitcast i32* {{.*}} to i8*
47 ; CHECK-BE-NEXT: [[GEP1:%[0-9]+]] = getelementptr i8, i8* [[BCC2]], i8 8
48 ; CHECK-BE-NEXT: [[BCL1:%[0-9]+]] = bitcast i8* [[GEP1]] to i64*
49 ; CHECK-BE-NEXT: [[GEP2:%[0-9]+]] = getelementptr i8, i8* [[BCC1]], i8 8
50 ; CHECK-BE-NEXT: [[BCL2:%[0-9]+]] = bitcast i8* [[GEP2]] to i64*
51 ; CHECK-BE-NEXT: [[LOAD1:%[0-9]+]] = load i64, i64* [[BCL1]]
52 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64* [[BCL2]]
53 ; CHECK-BE-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[LOAD1]], [[LOAD2]]
54 ; CHECK-BE-NEXT: br i1 [[ICMP]], label %endblock, label %res_block
56 %0 = bitcast i32* %buffer1 to i8*
57 %1 = bitcast i32* %buffer2 to i8*
58 %call = tail call signext i32 @memcmp(i8* %0, i8* %1, i64 16)
62 declare signext i32 @memcmp(i8* nocapture, i8* nocapture, i64) local_unnamed_addr #1
64 define signext i32 @test2(i32* nocapture readonly %buffer1, i32* nocapture readonly %buffer2) {
65 ; CHECK-LABEL: @test2(
66 ; CHECK: [[LOAD1:%[0-9]+]] = load i32, i32*
67 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i32, i32*
68 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i32 @llvm.bswap.i32(i32 [[LOAD1]])
69 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i32 @llvm.bswap.i32(i32 [[LOAD2]])
70 ; CHECK-NEXT: [[CMP1:%[0-9]+]] = icmp ugt i32 [[BSWAP1]], [[BSWAP2]]
71 ; CHECK-NEXT: [[CMP2:%[0-9]+]] = icmp ult i32 [[BSWAP1]], [[BSWAP2]]
72 ; CHECK-NEXT: [[Z1:%[0-9]+]] = zext i1 [[CMP1]] to i32
73 ; CHECK-NEXT: [[Z2:%[0-9]+]] = zext i1 [[CMP2]] to i32
74 ; CHECK-NEXT: [[SUB:%[0-9]+]] = sub i32 [[Z1]], [[Z2]]
75 ; CHECK-NEXT: ret i32 [[SUB]]
77 ; CHECK-BE-LABEL: @test2(
78 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i32, i32*
79 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i32, i32*
80 ; CHECK-BE-NEXT: [[CMP1:%[0-9]+]] = icmp ugt i32 [[LOAD1]], [[LOAD2]]
81 ; CHECK-BE-NEXT: [[CMP2:%[0-9]+]] = icmp ult i32 [[LOAD1]], [[LOAD2]]
82 ; CHECK-BE-NEXT: [[Z1:%[0-9]+]] = zext i1 [[CMP1]] to i32
83 ; CHECK-BE-NEXT: [[Z2:%[0-9]+]] = zext i1 [[CMP2]] to i32
84 ; CHECK-BE-NEXT: [[SUB:%[0-9]+]] = sub i32 [[Z1]], [[Z2]]
85 ; CHECK-BE-NEXT: ret i32 [[SUB]]
88 %0 = bitcast i32* %buffer1 to i8*
89 %1 = bitcast i32* %buffer2 to i8*
90 %call = tail call signext i32 @memcmp(i8* %0, i8* %1, i64 4)
94 define signext i32 @test3(i32* nocapture readonly %buffer1, i32* nocapture readonly %buffer2) {
95 ; CHECK: [[LOAD1:%[0-9]+]] = load i64, i64*
96 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64*
97 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD1]])
98 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i64 @llvm.bswap.i64(i64 [[LOAD2]])
99 ; CHECK-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[BSWAP1]], [[BSWAP2]]
100 ; CHECK-NEXT: br i1 [[ICMP]], label %loadbb1, label %res_block
102 ; CHECK-LABEL: res_block:{{.*}}
103 ; CHECK: [[ICMP2:%[0-9]+]] = icmp ult i64
104 ; CHECK-NEXT: [[SELECT:%[0-9]+]] = select i1 [[ICMP2]], i32 -1, i32 1
105 ; CHECK-NEXT: br label %endblock
107 ; CHECK-LABEL: loadbb1:{{.*}}
108 ; CHECK: [[LOAD1:%[0-9]+]] = load i32, i32*
109 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i32, i32*
110 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i32 @llvm.bswap.i32(i32 [[LOAD1]])
111 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i32 @llvm.bswap.i32(i32 [[LOAD2]])
112 ; CHECK-NEXT: [[ZEXT1:%[0-9]+]] = zext i32 [[BSWAP1]] to i64
113 ; CHECK-NEXT: [[ZEXT2:%[0-9]+]] = zext i32 [[BSWAP2]] to i64
114 ; CHECK-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[ZEXT1]], [[ZEXT2]]
115 ; CHECK-NEXT: br i1 [[ICMP]], label %loadbb2, label %res_block
117 ; CHECK-LABEL: loadbb2:{{.*}}
118 ; CHECK: [[LOAD1:%[0-9]+]] = load i16, i16*
119 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i16, i16*
120 ; CHECK-NEXT: [[BSWAP1:%[0-9]+]] = call i16 @llvm.bswap.i16(i16 [[LOAD1]])
121 ; CHECK-NEXT: [[BSWAP2:%[0-9]+]] = call i16 @llvm.bswap.i16(i16 [[LOAD2]])
122 ; CHECK-NEXT: [[ZEXT1:%[0-9]+]] = zext i16 [[BSWAP1]] to i64
123 ; CHECK-NEXT: [[ZEXT2:%[0-9]+]] = zext i16 [[BSWAP2]] to i64
124 ; CHECK-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[ZEXT1]], [[ZEXT2]]
125 ; CHECK-NEXT: br i1 [[ICMP]], label %loadbb3, label %res_block
127 ; CHECK-LABEL: loadbb3:{{.*}}
128 ; CHECK: [[LOAD1:%[0-9]+]] = load i8, i8*
129 ; CHECK-NEXT: [[LOAD2:%[0-9]+]] = load i8, i8*
130 ; CHECK-NEXT: [[ZEXT1:%[0-9]+]] = zext i8 [[LOAD1]] to i32
131 ; CHECK-NEXT: [[ZEXT2:%[0-9]+]] = zext i8 [[LOAD2]] to i32
132 ; CHECK-NEXT: [[SUB:%[0-9]+]] = sub i32 [[ZEXT1]], [[ZEXT2]]
133 ; CHECK-NEXT: br label %endblock
135 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i64, i64*
136 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i64, i64*
137 ; CHECK-BE-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[LOAD1]], [[LOAD2]]
138 ; CHECK-BE-NEXT: br i1 [[ICMP]], label %loadbb1, label %res_block
140 ; CHECK-BE-LABEL: res_block:{{.*}}
141 ; CHECK-BE: [[ICMP2:%[0-9]+]] = icmp ult i64
142 ; CHECK-BE-NEXT: [[SELECT:%[0-9]+]] = select i1 [[ICMP2]], i32 -1, i32 1
143 ; CHECK-BE-NEXT: br label %endblock
145 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i32, i32*
146 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i32, i32*
147 ; CHECK-BE-NEXT: [[ZEXT1:%[0-9]+]] = zext i32 [[LOAD1]] to i64
148 ; CHECK-BE-NEXT: [[ZEXT2:%[0-9]+]] = zext i32 [[LOAD2]] to i64
149 ; CHECK-BE-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[ZEXT1]], [[ZEXT2]]
150 ; CHECK-BE-NEXT: br i1 [[ICMP]], label %loadbb2, label %res_block
152 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i16, i16*
153 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i16, i16*
154 ; CHECK-BE-NEXT: [[ZEXT1:%[0-9]+]] = zext i16 [[LOAD1]] to i64
155 ; CHECK-BE-NEXT: [[ZEXT2:%[0-9]+]] = zext i16 [[LOAD2]] to i64
156 ; CHECK-BE-NEXT: [[ICMP:%[0-9]+]] = icmp eq i64 [[ZEXT1]], [[ZEXT2]]
157 ; CHECK-BE-NEXT: br i1 [[ICMP]], label %loadbb3, label %res_block
159 ; CHECK-BE: [[LOAD1:%[0-9]+]] = load i8, i8*
160 ; CHECK-BE-NEXT: [[LOAD2:%[0-9]+]] = load i8, i8*
161 ; CHECK-BE-NEXT: [[ZEXT1:%[0-9]+]] = zext i8 [[LOAD1]] to i32
162 ; CHECK-BE-NEXT: [[ZEXT2:%[0-9]+]] = zext i8 [[LOAD2]] to i32
163 ; CHECK-BE-NEXT: [[SUB:%[0-9]+]] = sub i32 [[ZEXT1]], [[ZEXT2]]
164 ; CHECK-BE-NEXT: br label %endblock
167 %0 = bitcast i32* %buffer1 to i8*
168 %1 = bitcast i32* %buffer2 to i8*
169 %call = tail call signext i32 @memcmp(i8* %0, i8* %1, i64 15)
172 ; CHECK: call = tail call signext i32 @memcmp
173 ; CHECK-BE: call = tail call signext i32 @memcmp
174 define signext i32 @test4(i32* nocapture readonly %buffer1, i32* nocapture readonly %buffer2) {
177 %0 = bitcast i32* %buffer1 to i8*
178 %1 = bitcast i32* %buffer2 to i8*
179 %call = tail call signext i32 @memcmp(i8* %0, i8* %1, i64 65)
183 define signext i32 @test5(i32* nocapture readonly %buffer1, i32* nocapture readonly %buffer2, i32 signext %SIZE) {
184 ; CHECK: call = tail call signext i32 @memcmp
185 ; CHECK-BE: call = tail call signext i32 @memcmp
187 %0 = bitcast i32* %buffer1 to i8*
188 %1 = bitcast i32* %buffer2 to i8*
189 %conv = sext i32 %SIZE to i64
190 %call = tail call signext i32 @memcmp(i8* %0, i8* %1, i64 %conv)