1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; icmp u/s (a ^ signmask), (b ^ signmask) --> icmp s/u a, b
6 define 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]]
13 %cmp = icmp slt i8 %a, %b
17 ; PR33138 - https://bugs.llvm.org/show_bug.cgi?id=33138
19 define <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: [[CMP:%.*]] = icmp ult <2 x i8> %x, %y
22 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
24 %a = xor <2 x i8> %x, <i8 128, i8 128>
25 %b = xor <2 x i8> %y, <i8 128, i8 128>
26 %cmp = icmp slt <2 x i8> %a, %b
30 ; Make sure that unsigned -> signed works too.
32 define i1 @ult_to_slt(i8 %x, i8 %y) {
33 ; CHECK-LABEL: @ult_to_slt(
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, %y
35 ; CHECK-NEXT: ret i1 [[CMP]]
39 %cmp = icmp ult i8 %a, %b
43 define <2 x i1> @ult_to_slt_splat(<2 x i8> %x, <2 x i8> %y) {
44 ; CHECK-LABEL: @ult_to_slt_splat(
45 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> %x, %y
46 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
48 %a = xor <2 x i8> %x, <i8 128, i8 128>
49 %b = xor <2 x i8> %y, <i8 128, i8 128>
50 %cmp = icmp ult <2 x i8> %a, %b
54 ; icmp u/s (a ^ maxsignval), (b ^ maxsignval) --> icmp s/u' a, b
56 define i1 @slt_to_ugt(i8 %x, i8 %y) {
57 ; CHECK-LABEL: @slt_to_ugt(
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, %y
59 ; CHECK-NEXT: ret i1 [[CMP]]
63 %cmp = icmp slt i8 %a, %b
67 define <2 x i1> @slt_to_ugt_splat(<2 x i8> %x, <2 x i8> %y) {
68 ; CHECK-LABEL: @slt_to_ugt_splat(
69 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x, %y
70 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
72 %a = xor <2 x i8> %x, <i8 127, i8 127>
73 %b = xor <2 x i8> %y, <i8 127, i8 127>
74 %cmp = icmp slt <2 x i8> %a, %b
78 ; Make sure that unsigned -> signed works too.
80 define i1 @ult_to_sgt(i8 %x, i8 %y) {
81 ; CHECK-LABEL: @ult_to_sgt(
82 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, %y
83 ; CHECK-NEXT: ret i1 [[CMP]]
87 %cmp = icmp ult i8 %a, %b
91 define <2 x i1> @ult_to_sgt_splat(<2 x i8> %x, <2 x i8> %y) {
92 ; CHECK-LABEL: @ult_to_sgt_splat(
93 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> %x, %y
94 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
96 %a = xor <2 x i8> %x, <i8 127, i8 127>
97 %b = xor <2 x i8> %y, <i8 127, i8 127>
98 %cmp = icmp ult <2 x i8> %a, %b
102 ; icmp u/s (a ^ signmask), C --> icmp s/u a, C'
104 define i1 @sge_to_ugt(i8 %x) {
105 ; CHECK-LABEL: @sge_to_ugt(
106 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, -114
107 ; CHECK-NEXT: ret i1 [[CMP]]
110 %cmp = icmp sge i8 %a, 15
114 define <2 x i1> @sge_to_ugt_splat(<2 x i8> %x) {
115 ; CHECK-LABEL: @sge_to_ugt_splat(
116 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x, <i8 -114, i8 -114>
117 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
119 %a = xor <2 x i8> %x, <i8 128, i8 128>
120 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
124 ; Make sure that unsigned -> signed works too.
126 define i1 @uge_to_sgt(i8 %x) {
127 ; CHECK-LABEL: @uge_to_sgt(
128 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, -114
129 ; CHECK-NEXT: ret i1 [[CMP]]
132 %cmp = icmp uge i8 %a, 15
136 define <2 x i1> @uge_to_sgt_splat(<2 x i8> %x) {
137 ; CHECK-LABEL: @uge_to_sgt_splat(
138 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -114, i8 -114>
139 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
141 %a = xor <2 x i8> %x, <i8 128, i8 128>
142 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
146 ; icmp u/s (a ^ maxsignval), C --> icmp s/u' a, C'
148 define i1 @sge_to_ult(i8 %x) {
149 ; CHECK-LABEL: @sge_to_ult(
150 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 %x, 113
151 ; CHECK-NEXT: ret i1 [[CMP]]
154 %cmp = icmp sge i8 %a, 15
158 define <2 x i1> @sge_to_ult_splat(<2 x i8> %x) {
159 ; CHECK-LABEL: @sge_to_ult_splat(
160 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 113, i8 113>
161 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
163 %a = xor <2 x i8> %x, <i8 127, i8 127>
164 %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15>
168 ; Make sure that unsigned -> signed works too.
170 define i1 @uge_to_slt(i8 %x) {
171 ; CHECK-LABEL: @uge_to_slt(
172 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, 113
173 ; CHECK-NEXT: ret i1 [[CMP]]
176 %cmp = icmp uge i8 %a, 15
180 define <2 x i1> @uge_to_slt_splat(<2 x i8> %x) {
181 ; CHECK-LABEL: @uge_to_slt_splat(
182 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 113, i8 113>
183 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
185 %a = xor <2 x i8> %x, <i8 127, i8 127>
186 %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15>
190 ; PR33138, part 2: https://bugs.llvm.org/show_bug.cgi?id=33138
191 ; Bitcast canonicalization ensures that we recognize the signbit constant.
193 define <8 x i1> @sgt_to_ugt_bitcasted_splat(<2 x i32> %x, <2 x i32> %y) {
194 ; CHECK-LABEL: @sgt_to_ugt_bitcasted_splat(
195 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> %x to <8 x i8>
196 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i32> %y to <8 x i8>
197 ; CHECK-NEXT: [[E:%.*]] = icmp ugt <8 x i8> [[TMP1]], [[TMP2]]
198 ; CHECK-NEXT: ret <8 x i1> [[E]]
200 %a = xor <2 x i32> %x, <i32 2155905152, i32 2155905152> ; 0x80808080
201 %b = xor <2 x i32> %y, <i32 2155905152, i32 2155905152>
202 %c = bitcast <2 x i32> %a to <8 x i8>
203 %d = bitcast <2 x i32> %b to <8 x i8>
204 %e = icmp sgt <8 x i8> %c, %d
208 ; Bitcast canonicalization ensures that we recognize the signbit constant.
210 define <2 x i1> @negative_simplify_splat(<4 x i8> %x) {
211 ; CHECK-LABEL: @negative_simplify_splat(
212 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
214 %a = or <4 x i8> %x, <i8 0, i8 128, i8 0, i8 128>
215 %b = bitcast <4 x i8> %a to <2 x i16>
216 %c = icmp sgt <2 x i16> %b, zeroinitializer