blob: 4b4d1ddbc5a86e58078e3e3ba60f63e3b7a76e5d [file] [log] [blame]
Sanjay Patel7ad3dbe2017-05-23 16:53:05 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4; icmp u/s (a ^ signmask), (b ^ signmask) --> icmp s/u a, b
5
6define i1 @slt_to_ult(i8 %x, i8 %y) {
7; CHECK-LABEL: @slt_to_ult(
8; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 %x, %y
9; CHECK-NEXT: ret i1 [[CMP]]
10;
11 %a = xor i8 %x, 128
12 %b = xor i8 %y, 128
13 %cmp = icmp slt i8 %a, %b
14 ret i1 %cmp
15}
16
17; PR33138 - https://bugs.llvm.org/show_bug.cgi?id=33138
18
19define <2 x i1> @slt_to_ult_splat(<2 x i8> %x, <2 x i8> %y) {
20; CHECK-LABEL: @slt_to_ult_splat(
21; CHECK-NEXT: [[A:%.*]] = xor <2 x i8> %x, <i8 -128, i8 -128>
22; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %y, <i8 -128, i8 -128>
23; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A]], [[B]]
24; CHECK-NEXT: ret <2 x i1> [[CMP]]
25;
26 %a = xor <2 x i8> %x, <i8 128, i8 128>
27 %b = xor <2 x i8> %y, <i8 128, i8 128>
28 %cmp = icmp slt <2 x i8> %a, %b
29 ret <2 x i1> %cmp
30}
31
32; Make sure that unsigned -> signed works too.
33
34define i1 @ult_to_slt(i8 %x, i8 %y) {
35; CHECK-LABEL: @ult_to_slt(
36; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, %y
37; CHECK-NEXT: ret i1 [[CMP]]
38;
39 %a = xor i8 %x, 128
40 %b = xor i8 %y, 128
41 %cmp = icmp ult i8 %a, %b
42 ret i1 %cmp
43}
44
45define <2 x i1> @ult_to_slt_splat(<2 x i8> %x, <2 x i8> %y) {
46; CHECK-LABEL: @ult_to_slt_splat(
47; CHECK-NEXT: [[A:%.*]] = xor <2 x i8> %x, <i8 -128, i8 -128>
48; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %y, <i8 -128, i8 -128>
49; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[A]], [[B]]
50; CHECK-NEXT: ret <2 x i1> [[CMP]]
51;
52 %a = xor <2 x i8> %x, <i8 128, i8 128>
53 %b = xor <2 x i8> %y, <i8 128, i8 128>
54 %cmp = icmp ult <2 x i8> %a, %b
55 ret <2 x i1> %cmp
56}
57
58; icmp u/s (a ^ maxsignval), (b ^ maxsignval) --> icmp s/u' a, b
59
60define i1 @slt_to_ugt(i8 %x, i8 %y) {
61; CHECK-LABEL: @slt_to_ugt(
62; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, %y
63; CHECK-NEXT: ret i1 [[CMP]]
64;
65 %a = xor i8 %x, 127
66 %b = xor i8 %y, 127
67 %cmp = icmp slt i8 %a, %b
68 ret i1 %cmp
69}
70
71define <2 x i1> @slt_to_ugt_splat(<2 x i8> %x, <2 x i8> %y) {
72; CHECK-LABEL: @slt_to_ugt_splat(
73; CHECK-NEXT: [[A:%.*]] = xor <2 x i8> %x, <i8 127, i8 127>
74; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %y, <i8 127, i8 127>
75; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A]], [[B]]
76; CHECK-NEXT: ret <2 x i1> [[CMP]]
77;
78 %a = xor <2 x i8> %x, <i8 127, i8 127>
79 %b = xor <2 x i8> %y, <i8 127, i8 127>
80 %cmp = icmp slt <2 x i8> %a, %b
81 ret <2 x i1> %cmp
82}
83
84; Make sure that unsigned -> signed works too.
85
86define i1 @ult_to_sgt(i8 %x, i8 %y) {
87; CHECK-LABEL: @ult_to_sgt(
88; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, %y
89; CHECK-NEXT: ret i1 [[CMP]]
90;
91 %a = xor i8 %x, 127
92 %b = xor i8 %y, 127
93 %cmp = icmp ult i8 %a, %b
94 ret i1 %cmp
95}
96
97define <2 x i1> @ult_to_sgt_splat(<2 x i8> %x, <2 x i8> %y) {
98; CHECK-LABEL: @ult_to_sgt_splat(
99; CHECK-NEXT: [[A:%.*]] = xor <2 x i8> %x, <i8 127, i8 127>
100; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %y, <i8 127, i8 127>
101; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[A]], [[B]]
102; CHECK-NEXT: ret <2 x i1> [[CMP]]
103;
104 %a = xor <2 x i8> %x, <i8 127, i8 127>
105 %b = xor <2 x i8> %y, <i8 127, i8 127>
106 %cmp = icmp ult <2 x i8> %a, %b
107 ret <2 x i1> %cmp
108}
109
110; icmp u/s (a ^ signmask), C --> icmp s/u a, C'
111
112define i1 @sge_to_ugt(i8 %x) {
113; CHECK-LABEL: @sge_to_ugt(
114; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, -114
115; CHECK-NEXT: ret i1 [[CMP]]
116;
117 %a = xor i8 %x, 128
118 %cmp = icmp sge i8 %a, 15
119 ret i1 %cmp
120}
121
122define <2 x i1> @sge_to_ugt_splat(<2 x i8> %x) {
123; CHECK-LABEL: @sge_to_ugt_splat(
124; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x, <i8 -114, i8 -114>
125; CHECK-NEXT: ret <2 x i1> [[CMP]]
126;
127 %a = xor <2 x i8> %x, <i8 128, i8 128>
128 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
129 ret <2 x i1> %cmp
130}
131
132; Make sure that unsigned -> signed works too.
133
134define i1 @uge_to_sgt(i8 %x) {
135; CHECK-LABEL: @uge_to_sgt(
136; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, -114
137; CHECK-NEXT: ret i1 [[CMP]]
138;
139 %a = xor i8 %x, 128
140 %cmp = icmp uge i8 %a, 15
141 ret i1 %cmp
142}
143
144define <2 x i1> @uge_to_sgt_splat(<2 x i8> %x) {
145; CHECK-LABEL: @uge_to_sgt_splat(
146; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -114, i8 -114>
147; CHECK-NEXT: ret <2 x i1> [[CMP]]
148;
149 %a = xor <2 x i8> %x, <i8 128, i8 128>
150 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
151 ret <2 x i1> %cmp
152}
153
154; icmp u/s (a ^ maxsignval), C --> icmp s/u' a, C'
155
156define i1 @sge_to_ult(i8 %x) {
157; CHECK-LABEL: @sge_to_ult(
158; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 %x, 113
159; CHECK-NEXT: ret i1 [[CMP]]
160;
161 %a = xor i8 %x, 127
162 %cmp = icmp sge i8 %a, 15
163 ret i1 %cmp
164}
165
166define <2 x i1> @sge_to_ult_splat(<2 x i8> %x) {
167; CHECK-LABEL: @sge_to_ult_splat(
168; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 113, i8 113>
169; CHECK-NEXT: ret <2 x i1> [[CMP]]
170;
171 %a = xor <2 x i8> %x, <i8 127, i8 127>
172 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
173 ret <2 x i1> %cmp
174}
175
176; Make sure that unsigned -> signed works too.
177
178define i1 @uge_to_slt(i8 %x) {
179; CHECK-LABEL: @uge_to_slt(
180; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, 113
181; CHECK-NEXT: ret i1 [[CMP]]
182;
183 %a = xor i8 %x, 127
184 %cmp = icmp uge i8 %a, 15
185 ret i1 %cmp
186}
187
188define <2 x i1> @uge_to_slt_splat(<2 x i8> %x) {
189; CHECK-LABEL: @uge_to_slt_splat(
190; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 113, i8 113>
191; CHECK-NEXT: ret <2 x i1> [[CMP]]
192;
193 %a = xor <2 x i8> %x, <i8 127, i8 127>
194 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
195 ret <2 x i1> %cmp
196}
197